diff options
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/thread.cxx | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/sal/osl/unx/thread.cxx b/sal/osl/unx/thread.cxx index ce5ece7c1d59..54e674dd4de5 100644 --- a/sal/osl/unx/thread.cxx +++ b/sal/osl/unx/thread.cxx @@ -23,6 +23,7 @@ #include <cstddef> #include <limits> #include <functional> +#include <mutex> #include "system.hxx" #include "unixerrnostring.hxx" @@ -598,7 +599,7 @@ struct HashEntry static HashEntry* HashTable[31]; const int HashSize = SAL_N_ELEMENTS(HashTable); -static pthread_mutex_t HashLock = PTHREAD_MUTEX_INITIALIZER; +static std::mutex HashLock; #if ! ((defined LINUX && !defined __FreeBSD_kernel__) || defined MACOSX || defined IOS) static oslThreadIdentifier LastIdent = 0; @@ -615,21 +616,18 @@ static oslThreadIdentifier lookupThreadId (pthread_t hThread) { HashEntry *pEntry; - pthread_mutex_lock(&HashLock); + std::unique_lock aGuard(HashLock); pEntry = HashTable[HASHID(hThread)]; while (pEntry != nullptr) { if (pthread_equal(pEntry->Handle, hThread)) { - pthread_mutex_unlock(&HashLock); return pEntry->Ident; } pEntry = pEntry->Next; } - pthread_mutex_unlock(&HashLock); - return 0; } @@ -637,7 +635,7 @@ static oslThreadIdentifier insertThreadId (pthread_t hThread) { HashEntry *pEntry, *pInsert = nullptr; - pthread_mutex_lock(&HashLock); + std::unique_lock aGuard(HashLock); pEntry = HashTable[HASHID(hThread)]; @@ -694,8 +692,6 @@ static oslThreadIdentifier insertThreadId (pthread_t hThread) HashTable[HASHID(hThread)] = pEntry; } - pthread_mutex_unlock(&HashLock); - return pEntry->Ident; } @@ -703,7 +699,7 @@ static void removeThreadId (pthread_t hThread) { HashEntry *pEntry, *pRemove = nullptr; - pthread_mutex_lock(&HashLock); + std::unique_lock aGuard(HashLock); pEntry = HashTable[HASHID(hThread)]; while (pEntry != nullptr) @@ -724,8 +720,6 @@ static void removeThreadId (pthread_t hThread) free(pEntry); } - - pthread_mutex_unlock(&HashLock); } oslThreadIdentifier SAL_CALL osl_getThreadIdentifier(oslThread Thread) |