e7feb557f4b1b59191d24df78eb8d34f9f523ce7
[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         /// Tests whether the thread is alive
13         static inline bool isThreadAlive( std::thread::id id )
14         {
15             HANDLE h = ::OpenThread( SYNCHRONIZE, FALSE, id );
16             if ( h == NULL )
17                 return false;
18             ::CloseHandle( h );
19             return true;
20         }
21
22         /// Default backoff::yield implementation
23         static inline void    backoff()
24         {
25             std::this_thread::yield();
26         }
27     }    // namespace Win32
28
29     using Win32::isThreadAlive;
30     using Win32::backoff;
31
32 }} // namespace cds::OS
33
34 #endif // #ifndef __CDS_OS_WIN_THREAD_H