Moved mutex/semaphore/thread implementation details to .cpp file.

This commit is contained in:
Branimir Karadžić
2017-02-15 22:14:17 -08:00
parent 3cda29b011
commit f7abed893f
8 changed files with 286 additions and 236 deletions

View File

@@ -7,17 +7,17 @@
#if BX_CONFIG_SUPPORTS_THREADING
#if 0 \
|| BX_PLATFORM_ANDROID \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_IOS \
#if BX_PLATFORM_ANDROID \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_NACL \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_OSX
# include <pthread.h>
#elif 0 \
|| BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_WINRT \
|| BX_PLATFORM_XBOX360
#elif BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_WINRT \
|| BX_PLATFORM_XBOX360 \
|| BX_PLATFORM_XBOXONE
# include <windows.h>
# include <errno.h>
#endif // BX_PLATFORM_
@@ -50,7 +50,7 @@ namespace bx
InitializeCriticalSectionEx(_mutex, 4000, 0); // docs recommend 4000 spincount as sane default
#else
InitializeCriticalSection(_mutex);
#endif
#endif // BX_PLATFORM_
return 0;
}
@@ -63,28 +63,36 @@ namespace bx
Mutex::Mutex()
{
BX_STATIC_ASSERT(sizeof(pthread_mutex_t) <= sizeof(m_internal) );
pthread_mutexattr_t attr;
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
#else
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
pthread_mutex_init(&m_handle, &attr);
#endif // BX_PLATFORM_
pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
pthread_mutex_init(handle, &attr);
}
Mutex::~Mutex()
{
pthread_mutex_destroy(&m_handle);
pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
pthread_mutex_destroy(handle);
}
void Mutex::lock()
{
pthread_mutex_lock(&m_handle);
pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
pthread_mutex_lock(handle);
}
void Mutex::unlock()
{
pthread_mutex_unlock(&m_handle);
pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
pthread_mutex_unlock(handle);
}
} // namespace bx