| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | #include "internal.h" |
| 29 | |
| 30 | #if defined(GLFW_BUILD_WIN32_THREAD) |
| 31 | |
| 32 | #include <assert.h> |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) |
| 40 | { |
| 41 | assert(tls->win32.allocated == GLFW_FALSE); |
| 42 | |
| 43 | tls->win32.index = TlsAlloc(); |
| 44 | if (tls->win32.index == TLS_OUT_OF_INDEXES) |
| 45 | { |
| 46 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to allocate TLS index"); |
| 47 | return GLFW_FALSE; |
| 48 | } |
| 49 | |
| 50 | tls->win32.allocated = GLFW_TRUE; |
| 51 | return GLFW_TRUE; |
| 52 | } |
| 53 | |
| 54 | void _glfwPlatformDestroyTls(_GLFWtls* tls) |
| 55 | { |
| 56 | if (tls->win32.allocated) |
| 57 | TlsFree(tls->win32.index); |
| 58 | memset(tls, 0, sizeof(_GLFWtls)); |
| 59 | } |
| 60 | |
| 61 | void* _glfwPlatformGetTls(_GLFWtls* tls) |
| 62 | { |
| 63 | assert(tls->win32.allocated == GLFW_TRUE); |
| 64 | return TlsGetValue(tls->win32.index); |
| 65 | } |
| 66 | |
| 67 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) |
| 68 | { |
| 69 | assert(tls->win32.allocated == GLFW_TRUE); |
| 70 | TlsSetValue(tls->win32.index, value); |
| 71 | } |
| 72 | |
| 73 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) |
| 74 | { |
| 75 | assert(mutex->win32.allocated == GLFW_FALSE); |
| 76 | InitializeCriticalSection(&mutex->win32.section); |
| 77 | return mutex->win32.allocated = GLFW_TRUE; |
| 78 | } |
| 79 | |
| 80 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) |
| 81 | { |
| 82 | if (mutex->win32.allocated) |
| 83 | DeleteCriticalSection(&mutex->win32.section); |
| 84 | memset(mutex, 0, sizeof(_GLFWmutex)); |
| 85 | } |
| 86 | |
| 87 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) |
| 88 | { |
| 89 | assert(mutex->win32.allocated == GLFW_TRUE); |
| 90 | EnterCriticalSection(&mutex->win32.section); |
| 91 | } |
| 92 | |
| 93 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) |
| 94 | { |
| 95 | assert(mutex->win32.allocated == GLFW_TRUE); |
| 96 | LeaveCriticalSection(&mutex->win32.section); |
| 97 | } |
| 98 | |
| 99 | #endif |
| 100 | |