This commit is contained in:
Branimir Karadžić
2018-03-11 18:30:43 -07:00
parent c57e759edb
commit cbd6d16338
4 changed files with 112 additions and 28 deletions

View File

@@ -8,7 +8,8 @@
#if BX_CONFIG_SUPPORTS_THREADING
#if BX_PLATFORM_ANDROID \
#if BX_CRT_NONE
#elif BX_PLATFORM_ANDROID \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_OSX \
@@ -24,7 +25,27 @@
namespace bx
{
#if BX_PLATFORM_WINDOWS \
#if BX_CRT_NONE
Mutex::Mutex()
{
BX_STATIC_ASSERT(sizeof(pthread_mutex_t) <= sizeof(m_internal) );
}
Mutex::~Mutex()
{
}
void Mutex::lock()
{
}
void Mutex::unlock()
{
}
#else
# if BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_XBOXONE \
|| BX_PLATFORM_WINRT
typedef CRITICAL_SECTION pthread_mutex_t;
@@ -49,11 +70,11 @@ namespace bx
inline int pthread_mutex_init(pthread_mutex_t* _mutex, pthread_mutexattr_t* /*_attr*/)
{
#if BX_PLATFORM_WINRT
# if BX_PLATFORM_WINRT
InitializeCriticalSectionEx(_mutex, 4000, 0); // docs recommend 4000 spincount as sane default
#else
# else
InitializeCriticalSection(_mutex);
#endif // BX_PLATFORM_
# endif // BX_PLATFORM_
return 0;
}
@@ -62,7 +83,7 @@ namespace bx
DeleteCriticalSection(_mutex);
return 0;
}
#endif // BX_PLATFORM_
# endif // BX_PLATFORM_
Mutex::Mutex()
{
@@ -70,13 +91,13 @@ namespace bx
pthread_mutexattr_t attr;
#if BX_PLATFORM_WINDOWS \
# if BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_XBOXONE \
|| BX_PLATFORM_WINRT
#else
# else
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#endif // BX_PLATFORM_
# endif // BX_PLATFORM_
pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
pthread_mutex_init(handle, &attr);
@@ -99,6 +120,7 @@ namespace bx
pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
pthread_mutex_unlock(handle);
}
#endif // BX_CRT_NONE
} // namespace bx