X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fos_thread.hpp;h=b17563fa5428d2ac80a4b5d18adf916c6c69ac75;hb=0e47f66f21683a18f34282e07efa85cdac4fe0e0;hp=7349255525276b47b36c3b5ba5aa7e3c4f4b6d81;hpb=a0e612d13d479d1b0e65d11037060b473c9d722f;p=apitrace diff --git a/common/os_thread.hpp b/common/os_thread.hpp index 7349255..b17563f 100644 --- a/common/os_thread.hpp +++ b/common/os_thread.hpp @@ -32,6 +32,7 @@ #ifndef _OS_THREAD_HPP_ #define _OS_THREAD_HPP_ + #ifdef _WIN32 #include #else @@ -41,6 +42,58 @@ namespace os { + class recursive_mutex + { + public: +#ifdef _WIN32 + typedef CRITICAL_SECTION native_handle_type; +#else + typedef pthread_mutex_t native_handle_type; +#endif + + recursive_mutex(void) { +#ifdef _WIN32 + InitializeCriticalSection(&_native_handle); +#else + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&_native_handle, NULL); + pthread_mutexattr_destroy(&attr); +#endif + } + + ~recursive_mutex() { +#ifdef _WIN32 + DeleteCriticalSection(&_native_handle); +#else + pthread_mutex_destroy(&_native_handle); +#endif + } + + inline void + lock(void) { +#ifdef _WIN32 + EnterCriticalSection(&_native_handle); +#else + pthread_mutex_lock(&_native_handle); +#endif + } + + inline void + unlock(void) { +#ifdef _WIN32 + LeaveCriticalSection(&_native_handle); +#else + pthread_mutex_unlock(&_native_handle); +#endif + } + + private: + native_handle_type _native_handle; + }; + + template class thread_specific_ptr {