Made cds::OS children namespaces inline, removed OS-specific syserror.h headers
[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     CDS_CXX11_INLINE_NAMESPACE 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     constexpr const posix::ThreadId c_NullThreadId = 0;
33
34 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
35     using posix::ThreadId;
36
37     using posix::getCurrentThreadId;
38     using posix::isThreadAlive;
39 #endif
40
41 }} // namespace cds::OS
42
43
44 #endif // #ifndef __CDS_OS_POSIX_THREAD_H