diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-13 11:09:07 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-14 13:45:47 +0200 |
commit | 60ba608b33b993ea9dc9cead84bd2d62f2ed50e1 (patch) | |
tree | 1f1308d5d26fb536636bfab40458c135683b8b8b /sal | |
parent | 06900403843e4afa413d0ca4e2ea6be761ac668a (diff) |
pthread_mutex_t->std::mutex in lookupThreadId
Change-Id: Ic9dfcfef5c604e778dfe527d627137042c8deb49
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134303
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
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) |