Replace NULL with nullptr
[libcds.git] / cds / os / posix / thread.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_OS_POSIX_THREAD_H
4 #define __CDS_OS_POSIX_THREAD_H
5
6 #include <pthread.h>
7 #include <signal.h>
8
9 namespace cds { namespace OS {
10     /// posix-related wrappers
11     namespace posix {
12
13         /// Posix thread id type
14         typedef std::thread::native_handle_type ThreadId;
15
16         /// Get current thread id
17         static inline ThreadId getCurrentThreadId()
18         { 
19             return pthread_self(); 
20         }
21
22         /// Checks if thread \p id is alive
23         static inline bool isThreadAlive( ThreadId id )
24         {
25             // if sig is zero, error checking is performed but no signal is actually sent.
26             // ESRCH - No thread could be found corresponding to that specified by the given thread ID
27             // Unresolved problem: Linux may crash on dead thread_id. Workaround unknown (except signal handler...)
28             return pthread_kill( id, 0 ) != ESRCH;
29         }
30     }    // namespace posix
31
32     using posix::ThreadId;
33     constexpr const ThreadId c_NullThreadId = 0;
34
35     using posix::getCurrentThreadId;
36     using posix::isThreadAlive;
37
38 }} // namespace cds::OS
39
40
41 #endif // #ifndef __CDS_OS_POSIX_THREAD_H