Revert "Replace cds::OS::ThreadId with std::thread::id, cds::OS::nullThreadId() with...
[libcds.git] / cds / os / win / thread.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_OS_WIN_THREAD_H
4 #define __CDS_OS_WIN_THREAD_H
5
6 #include <windows.h>
7
8 namespace cds { namespace OS {
9     /// Windows-specific functions
10     namespace Win32 {
11
12         /// OS-specific type of thread identifier
13         typedef DWORD           ThreadId;
14
15         /// Get current thread id
16         static inline ThreadId getCurrentThreadId()
17         {
18             return ::GetCurrentThreadId();
19         }
20
21         /// Tests whether the thread is alive
22         static inline bool isThreadAlive( ThreadId id )
23         {
24             HANDLE h = ::OpenThread( SYNCHRONIZE, FALSE, id );
25             if ( h == NULL )
26                 return false;
27             ::CloseHandle( h );
28             return true;
29         }
30
31         /// Default backoff::yield implementation
32         static inline void    backoff()
33         {
34             std::this_thread::yield();
35         }
36     }    // namespace Win32
37
38     using Win32::ThreadId;
39     CDS_CONSTEXPR const ThreadId c_NullThreadId = 0;
40
41     using Win32::getCurrentThreadId;
42     using Win32::isThreadAlive;
43     using Win32::backoff;
44
45 }} // namespace cds::OS
46
47 #endif // #ifndef __CDS_OS_WIN_THREAD_H