|
|
Home » U++ Library support » U++ Core » Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods [message #30583 is a reply to message #30577] |
Mon, 10 January 2011 15:35 |
|
Ok, Exists 2 variants:
1. The first variant, proposed by me, which calls system API:
class Thread : NoCopy {
#ifdef PLATFORM_WIN32
HANDLE handle;
#endif
#ifdef PLATFORM_POSIX
pthread_t handle;
#endif
public:
bool Run(Callback cb);
void Detach();
int Wait();
bool IsOpen() const { return handle; }
#ifdef PLATFORM_WIN32
typedef HANDLE Handle;
typedef DWORD Id;
#endif
#ifdef PLATFORM_POSIX
typedef pthread_t Handle;
typedef pthread_t Id;
#endif
Handle GetHandle() const { return handle; }
void Priority(int percent); // 0 = lowest, 100 = normal
static void Start(Callback cb);
static void Sleep(int ms);
static bool IsST();
static bool IsMain();
static int GetCount();
static void ShutdownThreads();
static bool IsShutdownThreads();
#ifdef PLATFORM_WIN32
static Handle GetCurrentHandle(){
return GetCurrentThread();
}
static Id GetCurrentId(){
return ::GetCurrentThreadId();
};
static inline
#elif defined(PLATFORM_POSIX)
static Handle GetCurrentHandle(){
return pthread_self();
}
static Id GetCurrentId(){
return pthread_self();
};
#endif
Thread();
~Thread();
private:
void operator=(const Thread&);
Thread(const Thread&);
};
2. The second variant, customized, proposed by Mirek, which need to be faster than call system API is:
static thread__ bool __sThreadId;
...
class Thread : NoCopy {
#ifdef PLATFORM_WIN32
HANDLE handle;
#endif
#ifdef PLATFORM_POSIX
pthread_t handle;
#endif
public:
bool Run(Callback cb);
void Detach();
int Wait();
bool IsOpen() const { return handle; }
#ifdef PLATFORM_WIN32
typedef HANDLE Handle;
#endif
#ifdef PLATFORM_POSIX
typedef pthread_t Handle;
#endif
typedef qword Id;
Handle GetHandle() const { return handle; }
void Priority(int percent); // 0 = lowest, 100 = normal
static void Start(Callback cb);
static void Sleep(int ms);
static bool IsST();
static bool IsMain();
static int GetCount();
static void ShutdownThreads();
static bool IsShutdownThreads();
#ifdef PLATFORM_WIN32
static Handle GetCurrentHandle(){
return GetCurrentThread();
}
#elif defined(PLATFORM_POSIX)
static Handle GetCurrentHandle(){
return pthread_self();
}
#endif
static inline Id GetCurrentId(){
return (qword)(&__sThreadId);
};
Thread();
~Thread();
private:
void operator=(const Thread&);
Thread(const Thread&);
};
The "static thread__ bool __sThreadId" and "GetCurrentId()" menthod body in the second variant can be placed in cpp file.
What is the best solution?
Thank you Mirek for Hint!
|
|
|
|
|
Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Fri, 07 January 2011 16:38
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: mirek on Sat, 08 January 2011 13:07
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Sun, 09 January 2011 22:28
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: mirek on Sun, 09 January 2011 22:49
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Mon, 10 January 2011 15:35
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: mirek on Mon, 10 January 2011 17:48
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Mon, 10 January 2011 19:13
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: mirek on Tue, 11 January 2011 14:49
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Tue, 11 January 2011 16:11
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: mirek on Wed, 12 January 2011 09:49
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Wed, 12 January 2011 12:36
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: mirek on Wed, 12 January 2011 20:40
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Thu, 13 January 2011 11:47
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: mirek on Thu, 13 January 2011 20:51
|
|
|
Re: Thread::GetCurrentThreadId() and Thread::GetCurrentThreadHandle() new methods
By: tojocky on Fri, 14 January 2011 08:12
|
Goto Forum:
Current Time: Tue May 21 09:52:31 CEST 2024
Total time taken to generate the page: 0.01725 seconds
|
|
|