Revert "Work on replacing pthread with std::thread"
This reverts commit f82ebe19bd
.
This commit is contained in:
parent
1f29d41b08
commit
c239ac5220
|
@ -998,7 +998,7 @@
|
|||
#define AS_MAX_PORTABILITY
|
||||
#endif
|
||||
#define AS_LINUX
|
||||
#define AS_STD_THREADS
|
||||
#define AS_POSIX_THREADS
|
||||
|
||||
#if !( ( (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) )
|
||||
// Only with GCC 4.1 was the atomic instructions available
|
||||
|
@ -1273,7 +1273,7 @@
|
|||
// If the form of threads to use hasn't been chosen
|
||||
// then the library will be compiled without support
|
||||
// for multithreading
|
||||
#if !defined(AS_POSIX_THREADS) && !defined(AS_WINDOWS_THREADS) && !defined(AS_STD_THREADS)
|
||||
#if !defined(AS_POSIX_THREADS) && !defined(AS_WINDOWS_THREADS)
|
||||
#define AS_NO_THREADS
|
||||
#endif
|
||||
|
||||
|
|
|
@ -179,45 +179,6 @@ protected:
|
|||
// but it gives a compiler error on MSVC6 so I'm leaving it outside
|
||||
static const asUINT maxReaders = 10;
|
||||
|
||||
#elif defined(AS_STD_THREADS)
|
||||
|
||||
END_AS_NAMESPACE
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
BEGIN_AS_NAMESPACE
|
||||
|
||||
class asCThreadCriticalSection
|
||||
{
|
||||
public:
|
||||
asCThreadCriticalSection();
|
||||
~asCThreadCriticalSection();
|
||||
|
||||
void Enter();
|
||||
void Leave();
|
||||
bool TryEnter();
|
||||
|
||||
protected:
|
||||
std::mutex _mutex;
|
||||
};
|
||||
|
||||
class asCThreadReadWriteLock
|
||||
{
|
||||
public:
|
||||
asCThreadReadWriteLock();
|
||||
~asCThreadReadWriteLock();
|
||||
|
||||
void AcquireExclusive();
|
||||
void ReleaseExclusive();
|
||||
bool TryAcquireExclusive();
|
||||
|
||||
void AcquireShared();
|
||||
void ReleaseShared();
|
||||
bool TryAcquireShared();
|
||||
protected:
|
||||
std::shared_mutex _mutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -226,10 +226,6 @@ asCThreadManager::~asCThreadManager()
|
|||
#endif
|
||||
}
|
||||
|
||||
#if defined(AS_STD_THREADS)
|
||||
thread_local asCThreadLocalData *std_tld;
|
||||
#endif
|
||||
|
||||
int asCThreadManager::CleanupLocalData()
|
||||
{
|
||||
if( threadManager == 0 )
|
||||
|
@ -241,9 +237,7 @@ int asCThreadManager::CleanupLocalData()
|
|||
#elif defined AS_WINDOWS_THREADS
|
||||
#if !defined(_MSC_VER) || !(WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP)
|
||||
asCThreadLocalData *tld = (asCThreadLocalData*)TlsGetValue((DWORD)threadManager->tlsKey);
|
||||
#endif
|
||||
#elif defined(AS_STD_THREADS)
|
||||
auto tld = std_tld;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if( tld == 0 )
|
||||
|
@ -305,13 +299,7 @@ asCThreadLocalData *asCThreadManager::GetLocalData()
|
|||
tld = asNEW(asCThreadLocalData)();
|
||||
TlsSetValue((DWORD)threadManager->tlsKey, tld);
|
||||
}
|
||||
#endif
|
||||
#elif defined(AS_STD_THREADS)
|
||||
if(std_tld == nullptr)
|
||||
{
|
||||
std_tld = asNEW(asCThreadLocalData)();
|
||||
}
|
||||
auto tld = std_tld;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return tld;
|
||||
|
@ -367,8 +355,6 @@ void asCThreadCriticalSection::Enter()
|
|||
pthread_mutex_lock(&cs);
|
||||
#elif defined AS_WINDOWS_THREADS
|
||||
EnterCriticalSection(&cs);
|
||||
#elif defined(AS_STD_THREADS)
|
||||
_mutex.lock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -378,8 +364,6 @@ void asCThreadCriticalSection::Leave()
|
|||
pthread_mutex_unlock(&cs);
|
||||
#elif defined AS_WINDOWS_THREADS
|
||||
LeaveCriticalSection(&cs);
|
||||
#elif defined(AS_STD_THREADS)
|
||||
_mutex.unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -389,8 +373,6 @@ bool asCThreadCriticalSection::TryEnter()
|
|||
return !pthread_mutex_trylock(&cs);
|
||||
#elif defined AS_WINDOWS_THREADS
|
||||
return TryEnterCriticalSection(&cs) ? true : false;
|
||||
#elif defined(AS_STD_THREADS)
|
||||
return _mutex.try_lock();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
|
@ -445,8 +427,6 @@ void asCThreadReadWriteLock::AcquireExclusive()
|
|||
// Allow another writer to lock. It will only be able to
|
||||
// lock the readers when this writer releases them anyway.
|
||||
LeaveCriticalSection(&writeLock);
|
||||
#elif defined(AS_STD_THREADS)
|
||||
_mutex.lock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -457,8 +437,6 @@ void asCThreadReadWriteLock::ReleaseExclusive()
|
|||
#elif defined AS_WINDOWS_THREADS
|
||||
// Release all readers at once
|
||||
ReleaseSemaphore(readLocks, maxReaders, 0);
|
||||
#elif defined(AS_STD_THREADS)
|
||||
_mutex.unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -469,8 +447,6 @@ void asCThreadReadWriteLock::AcquireShared()
|
|||
#elif defined AS_WINDOWS_THREADS
|
||||
// Lock a reader slot
|
||||
WaitForSingleObjectEx(readLocks, INFINITE, FALSE);
|
||||
#elif defined(AS_STD_THREADS)
|
||||
_mutex.lock_shared();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -481,8 +457,6 @@ void asCThreadReadWriteLock::ReleaseShared()
|
|||
#elif defined AS_WINDOWS_THREADS
|
||||
// Release the reader slot
|
||||
ReleaseSemaphore(readLocks, 1, 0);
|
||||
#elif defined(AS_STD_THREADS)
|
||||
_mutex.unlock_shared();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue