Fixed min/max macro problem in MS VC++
[libcds.git] / cds / os / win / thread.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_OS_WIN_THREAD_H
4 #define CDSLIB_OS_WIN_THREAD_H
5
6 #define NOMINMAX
7 #include <windows.h>
8
9 namespace cds { namespace OS {
10     /// Windows-specific functions
11     CDS_CXX11_INLINE_NAMESPACE namespace Win32 {
12
13         /// OS-specific type of thread identifier
14         typedef DWORD           ThreadId;
15
16         /// Get current thread id
17         static inline ThreadId get_current_thread_id()
18         {
19             return ::GetCurrentThreadId();
20         }
21
22         /// Tests whether the thread is alive
23         static inline bool is_thread_alive( ThreadId id )
24         {
25             HANDLE h = ::OpenThread( SYNCHRONIZE, FALSE, id );
26             if ( h == nullptr )
27                 return false;
28             ::CloseHandle( h );
29             return true;
30         }
31     }    // namespace Win32
32
33     //@cond
34     CDS_CONSTEXPR const Win32::ThreadId c_NullThreadId = 0;
35
36 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
37     using Win32::ThreadId;
38     using Win32::get_current_thread_id;
39     using Win32::is_thread_alive;
40 #endif
41     //@endcond
42
43 }} // namespace cds::OS
44
45 #endif // #ifndef CDSLIB_OS_WIN_THREAD_H