Attempt at fixing segfault with new std threads impl

This commit is contained in:
Deukhoofd 2022-02-11 13:15:08 +01:00
parent 145848c76c
commit ee2f629911
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 13 additions and 9 deletions

View File

@ -198,7 +198,7 @@ public:
bool TryEnter(); bool TryEnter();
protected: protected:
std::mutex _mutex; std::unique_ptr<std::mutex> _mutex;
}; };
class asCThreadReadWriteLock class asCThreadReadWriteLock
@ -215,7 +215,7 @@ public:
void ReleaseShared(); void ReleaseShared();
bool TryAcquireShared(); bool TryAcquireShared();
protected: protected:
std::shared_mutex _mutex; std::unique_ptr<std::shared_mutex> _mutex;
}; };
#endif #endif

View File

@ -349,6 +349,8 @@ asCThreadCriticalSection::asCThreadCriticalSection()
// MinGW also only defines this version // MinGW also only defines this version
InitializeCriticalSection(&cs); InitializeCriticalSection(&cs);
#endif #endif
#elif defined AS_STD_THREADS
_mutex = std::make_unique<std::mutex>();
#endif #endif
} }
@ -368,7 +370,7 @@ void asCThreadCriticalSection::Enter()
#elif defined AS_WINDOWS_THREADS #elif defined AS_WINDOWS_THREADS
EnterCriticalSection(&cs); EnterCriticalSection(&cs);
#elif defined(AS_STD_THREADS) #elif defined(AS_STD_THREADS)
_mutex.lock(); _mutex->lock();
#endif #endif
} }
@ -379,7 +381,7 @@ void asCThreadCriticalSection::Leave()
#elif defined AS_WINDOWS_THREADS #elif defined AS_WINDOWS_THREADS
LeaveCriticalSection(&cs); LeaveCriticalSection(&cs);
#elif defined(AS_STD_THREADS) #elif defined(AS_STD_THREADS)
_mutex.unlock(); _mutex->unlock();
#endif #endif
} }
@ -390,7 +392,7 @@ bool asCThreadCriticalSection::TryEnter()
#elif defined AS_WINDOWS_THREADS #elif defined AS_WINDOWS_THREADS
return TryEnterCriticalSection(&cs) ? true : false; return TryEnterCriticalSection(&cs) ? true : false;
#elif defined(AS_STD_THREADS) #elif defined(AS_STD_THREADS)
return _mutex.try_lock(); return _mutex->try_lock();
#else #else
return true; return true;
#endif #endif
@ -414,6 +416,8 @@ asCThreadReadWriteLock::asCThreadReadWriteLock()
readLocks = CreateSemaphoreW(NULL, maxReaders, maxReaders, 0); readLocks = CreateSemaphoreW(NULL, maxReaders, maxReaders, 0);
InitializeCriticalSection(&writeLock); InitializeCriticalSection(&writeLock);
#endif #endif
#elif defined AS_STD_THREADS
_mutex = std::make_unique<std::shared_mutex>();
#endif #endif
} }
@ -446,7 +450,7 @@ void asCThreadReadWriteLock::AcquireExclusive()
// lock the readers when this writer releases them anyway. // lock the readers when this writer releases them anyway.
LeaveCriticalSection(&writeLock); LeaveCriticalSection(&writeLock);
#elif defined(AS_STD_THREADS) #elif defined(AS_STD_THREADS)
_mutex.lock(); _mutex->lock();
#endif #endif
} }
@ -458,7 +462,7 @@ void asCThreadReadWriteLock::ReleaseExclusive()
// Release all readers at once // Release all readers at once
ReleaseSemaphore(readLocks, maxReaders, 0); ReleaseSemaphore(readLocks, maxReaders, 0);
#elif defined(AS_STD_THREADS) #elif defined(AS_STD_THREADS)
_mutex.unlock(); _mutex->unlock();
#endif #endif
} }
@ -470,7 +474,7 @@ void asCThreadReadWriteLock::AcquireShared()
// Lock a reader slot // Lock a reader slot
WaitForSingleObjectEx(readLocks, INFINITE, FALSE); WaitForSingleObjectEx(readLocks, INFINITE, FALSE);
#elif defined(AS_STD_THREADS) #elif defined(AS_STD_THREADS)
_mutex.lock_shared(); _mutex->lock_shared();
#endif #endif
} }
@ -482,7 +486,7 @@ void asCThreadReadWriteLock::ReleaseShared()
// Release the reader slot // Release the reader slot
ReleaseSemaphore(readLocks, 1, 0); ReleaseSemaphore(readLocks, 1, 0);
#elif defined(AS_STD_THREADS) #elif defined(AS_STD_THREADS)
_mutex.unlock_shared(); _mutex->unlock_shared();
#endif #endif
} }