diff options
author | Chris Robinson <[email protected]> | 2018-11-26 20:34:16 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-26 20:34:16 -0800 |
commit | bf9db1fe3d611137448c0eb99978c8906531ffc1 (patch) | |
tree | 8b63692a566aed2922b56126106c4e68412a0c79 | |
parent | ecab90802a62266687cf8aeaa61dc2811ce191e7 (diff) |
Remove althrd_t from Windows
-rw-r--r-- | Alc/helpers.cpp | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | common/threads.cpp | 76 | ||||
-rw-r--r-- | common/threads.h | 11 | ||||
-rw-r--r-- | common/uintmap.h | 35 |
5 files changed, 5 insertions, 119 deletions
diff --git a/Alc/helpers.cpp b/Alc/helpers.cpp index d06a4807..8a2a851d 100644 --- a/Alc/helpers.cpp +++ b/Alc/helpers.cpp @@ -118,7 +118,6 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_GUID, 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x #include "alu.h" #include "cpu_caps.h" #include "fpu_modes.h" -#include "uintmap.h" #include "vector.h" #include "compat.h" #include "threads.h" diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bbbc561..26476a67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -709,7 +709,6 @@ SET(COMMON_OBJS common/math_defs.h common/threads.cpp common/threads.h - common/uintmap.h common/vecmat.cpp common/vecmat.h ) diff --git a/common/threads.cpp b/common/threads.cpp index 7d44c012..86fbb7b5 100644 --- a/common/threads.cpp +++ b/common/threads.cpp @@ -26,8 +26,6 @@ #include <string.h> #include <errno.h> -#include "uintmap.h" - #ifndef UNUSED #if defined(__cplusplus) @@ -51,15 +49,6 @@ #include <mmsystem.h> -/* An associative map of uint:void* pairs. The key is the unique Thread ID and - * the value is the thread HANDLE. The thread ID is passed around as the - * althrd_t since there is only one ID per thread, whereas a thread may be - * referenced by multiple different HANDLEs. This map allows retrieving the - * original handle which is needed to join the thread and get its return value. - */ -static ThrSafeMap<DWORD,HANDLE> ThrdIdHandle{}; - - void althrd_setname(const char *name) { #if defined(_MSC_VER) @@ -89,71 +78,6 @@ void althrd_setname(const char *name) } -typedef struct thread_cntr { - althrd_start_t func; - void *arg; -} thread_cntr; - -static DWORD WINAPI althrd_starter(void *arg) -{ - thread_cntr cntr; - memcpy(&cntr, arg, sizeof(cntr)); - free(arg); - - return (DWORD)((*cntr.func)(cntr.arg)); -} - - -int althrd_create(althrd_t *thr, althrd_start_t func, void *arg) -{ - thread_cntr *cntr; - DWORD thrid; - HANDLE hdl; - - cntr = static_cast<thread_cntr*>(malloc(sizeof(*cntr))); - if(!cntr) return althrd_nomem; - - cntr->func = func; - cntr->arg = arg; - - hdl = CreateThread(NULL, THREAD_STACK_SIZE, althrd_starter, cntr, 0, &thrid); - if(!hdl) - { - free(cntr); - return althrd_error; - } - ThrdIdHandle.InsertEntry(thrid, hdl); - - *thr = thrid; - return althrd_success; -} - -int althrd_detach(althrd_t thr) -{ - HANDLE hdl = ThrdIdHandle.RemoveKey(thr); - if(!hdl) return althrd_error; - - CloseHandle(hdl); - return althrd_success; -} - -int althrd_join(althrd_t thr, int *res) -{ - DWORD code; - - HANDLE hdl = ThrdIdHandle.RemoveKey(thr); - if(!hdl) return althrd_error; - - WaitForSingleObject(hdl, INFINITE); - GetExitCodeThread(hdl, &code); - CloseHandle(hdl); - - if(res != NULL) - *res = (int)code; - return althrd_success; -} - - int almtx_init(almtx_t *mtx, int type) { if(!mtx) return althrd_error; diff --git a/common/threads.h b/common/threads.h index 8fd1093d..a5f6ce45 100644 --- a/common/threads.h +++ b/common/threads.h @@ -30,14 +30,11 @@ enum { almtx_recursive = 1, }; -typedef int (*althrd_start_t)(void*); - #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include <windows.h> -typedef DWORD althrd_t; typedef CRITICAL_SECTION almtx_t; typedef HANDLE alsem_t; @@ -81,6 +78,8 @@ typedef dispatch_semaphore_t alsem_t; typedef sem_t alsem_t; #endif /* __APPLE__ */ +typedef int (*althrd_start_t)(void*); + inline void althrd_yield(void) { @@ -102,12 +101,12 @@ inline int almtx_unlock(almtx_t *mtx) return althrd_success; } -#endif - - int althrd_create(althrd_t *thr, althrd_start_t func, void *arg); int althrd_detach(althrd_t thr); int althrd_join(althrd_t thr, int *res); + +#endif + void althrd_setname(const char *name); int almtx_init(almtx_t *mtx, int type); diff --git a/common/uintmap.h b/common/uintmap.h deleted file mode 100644 index 0646d2b5..00000000 --- a/common/uintmap.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef AL_UINTMAP_H -#define AL_UINTMAP_H - -#include <unordered_map> -#include <mutex> - -#include "AL/al.h" - -template<typename T0, typename T1> -class ThrSafeMap { - std::unordered_map<T0, T1> mValues; - std::mutex mLock; - -public: - void InsertEntry(T0 key, T1 value) noexcept - { - std::lock_guard<std::mutex> _{mLock}; - mValues[key] = value; - } - - T1 RemoveKey(T0 key) noexcept - { - T1 retval{}; - - std::lock_guard<std::mutex> _{mLock}; - auto iter = mValues.find(key); - if(iter != mValues.end()) - retval = iter->second; - mValues.erase(iter); - - return retval; - } -}; - -#endif /* AL_UINTMAP_H */ |