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
|
#define AS_MAX_PORTABILITY
|
||||||
#endif
|
#endif
|
||||||
#define AS_LINUX
|
#define AS_LINUX
|
||||||
#define AS_STD_THREADS
|
#define AS_POSIX_THREADS
|
||||||
|
|
||||||
#if !( ( (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) )
|
#if !( ( (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) )
|
||||||
// Only with GCC 4.1 was the atomic instructions available
|
// 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
|
// If the form of threads to use hasn't been chosen
|
||||||
// then the library will be compiled without support
|
// then the library will be compiled without support
|
||||||
// for multithreading
|
// 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
|
#define AS_NO_THREADS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -179,45 +179,6 @@ protected:
|
||||||
// but it gives a compiler error on MSVC6 so I'm leaving it outside
|
// but it gives a compiler error on MSVC6 so I'm leaving it outside
|
||||||
static const asUINT maxReaders = 10;
|
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
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -226,10 +226,6 @@ asCThreadManager::~asCThreadManager()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(AS_STD_THREADS)
|
|
||||||
thread_local asCThreadLocalData *std_tld;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int asCThreadManager::CleanupLocalData()
|
int asCThreadManager::CleanupLocalData()
|
||||||
{
|
{
|
||||||
if( threadManager == 0 )
|
if( threadManager == 0 )
|
||||||
|
@ -242,8 +238,6 @@ int asCThreadManager::CleanupLocalData()
|
||||||
#if !defined(_MSC_VER) || !(WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP)
|
#if !defined(_MSC_VER) || !(WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP)
|
||||||
asCThreadLocalData *tld = (asCThreadLocalData*)TlsGetValue((DWORD)threadManager->tlsKey);
|
asCThreadLocalData *tld = (asCThreadLocalData*)TlsGetValue((DWORD)threadManager->tlsKey);
|
||||||
#endif
|
#endif
|
||||||
#elif defined(AS_STD_THREADS)
|
|
||||||
auto tld = std_tld;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( tld == 0 )
|
if( tld == 0 )
|
||||||
|
@ -306,12 +300,6 @@ asCThreadLocalData *asCThreadManager::GetLocalData()
|
||||||
TlsSetValue((DWORD)threadManager->tlsKey, tld);
|
TlsSetValue((DWORD)threadManager->tlsKey, tld);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#elif defined(AS_STD_THREADS)
|
|
||||||
if(std_tld == nullptr)
|
|
||||||
{
|
|
||||||
std_tld = asNEW(asCThreadLocalData)();
|
|
||||||
}
|
|
||||||
auto tld = std_tld;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return tld;
|
return tld;
|
||||||
|
@ -367,8 +355,6 @@ void asCThreadCriticalSection::Enter()
|
||||||
pthread_mutex_lock(&cs);
|
pthread_mutex_lock(&cs);
|
||||||
#elif defined AS_WINDOWS_THREADS
|
#elif defined AS_WINDOWS_THREADS
|
||||||
EnterCriticalSection(&cs);
|
EnterCriticalSection(&cs);
|
||||||
#elif defined(AS_STD_THREADS)
|
|
||||||
_mutex.lock();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,8 +364,6 @@ void asCThreadCriticalSection::Leave()
|
||||||
pthread_mutex_unlock(&cs);
|
pthread_mutex_unlock(&cs);
|
||||||
#elif defined AS_WINDOWS_THREADS
|
#elif defined AS_WINDOWS_THREADS
|
||||||
LeaveCriticalSection(&cs);
|
LeaveCriticalSection(&cs);
|
||||||
#elif defined(AS_STD_THREADS)
|
|
||||||
_mutex.unlock();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,8 +373,6 @@ bool asCThreadCriticalSection::TryEnter()
|
||||||
return !pthread_mutex_trylock(&cs);
|
return !pthread_mutex_trylock(&cs);
|
||||||
#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)
|
|
||||||
return _mutex.try_lock();
|
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
@ -445,8 +427,6 @@ void asCThreadReadWriteLock::AcquireExclusive()
|
||||||
// Allow another writer to lock. It will only be able to
|
// Allow another writer to lock. It will only be able to
|
||||||
// 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)
|
|
||||||
_mutex.lock();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,8 +437,6 @@ void asCThreadReadWriteLock::ReleaseExclusive()
|
||||||
#elif defined AS_WINDOWS_THREADS
|
#elif defined AS_WINDOWS_THREADS
|
||||||
// Release all readers at once
|
// Release all readers at once
|
||||||
ReleaseSemaphore(readLocks, maxReaders, 0);
|
ReleaseSemaphore(readLocks, maxReaders, 0);
|
||||||
#elif defined(AS_STD_THREADS)
|
|
||||||
_mutex.unlock();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,8 +447,6 @@ void asCThreadReadWriteLock::AcquireShared()
|
||||||
#elif defined AS_WINDOWS_THREADS
|
#elif defined AS_WINDOWS_THREADS
|
||||||
// Lock a reader slot
|
// Lock a reader slot
|
||||||
WaitForSingleObjectEx(readLocks, INFINITE, FALSE);
|
WaitForSingleObjectEx(readLocks, INFINITE, FALSE);
|
||||||
#elif defined(AS_STD_THREADS)
|
|
||||||
_mutex.lock_shared();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,8 +457,6 @@ void asCThreadReadWriteLock::ReleaseShared()
|
||||||
#elif defined AS_WINDOWS_THREADS
|
#elif defined AS_WINDOWS_THREADS
|
||||||
// Release the reader slot
|
// Release the reader slot
|
||||||
ReleaseSemaphore(readLocks, 1, 0);
|
ReleaseSemaphore(readLocks, 1, 0);
|
||||||
#elif defined(AS_STD_THREADS)
|
|
||||||
_mutex.unlock_shared();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue