1 2 // Copyright 2018 - 2021 Michael D. Parker 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module bindbc.sdl.bind.sdlmutex; 8 9 import bindbc.sdl.config; 10 11 enum SDL_MUTEX_TIMEOUT = 1; 12 enum SDL_MUTEX_MAXWAIT = uint.max; 13 14 struct SDL_mutex; 15 struct SDL_sem; 16 struct SDL_cond; 17 18 19 static if(staticBinding) { 20 extern(C) @nogc nothrow { 21 SDL_mutex* SDL_CreateMutex(); 22 int SDL_LockMutex(SDL_mutex* mutex); 23 int SDL_TryLockMutex(SDL_mutex* mutex); 24 int SDL_UnlockMutex(SDL_mutex* mutex); 25 void SDL_DestroyMutex(SDL_mutex* mutex); 26 27 SDL_sem* SDL_CreateSemaphore(uint initial_value); 28 void SDL_DestroySemaphore(SDL_sem* sem); 29 int SDL_SemWait(SDL_sem* sem); 30 int SDL_SemWaitTimeout(SDL_sem* sem, uint ms); 31 int SDL_SemPost(SDL_sem* sem); 32 uint SDL_SemValue(SDL_sem* sem); 33 34 SDL_cond* SDL_CreateCond(); 35 void SDL_DestroyCond(SDL_cond* cond); 36 int SDL_CondSignal(SDL_cond* cond); 37 int SDL_CondBroadcast(SDL_cond* cond); 38 int SDL_CondWait(SDL_cond* cond,SDL_mutex*); 39 int SDL_CondWaitTimeout(SDL_cond* cond, SDL_mutex* mutex, uint ms); 40 } 41 } 42 else { 43 extern(C) @nogc nothrow { 44 alias pSDL_CreateMutex = SDL_mutex* function(); 45 alias pSDL_LockMutex = int function(SDL_mutex* mutex); 46 alias pSDL_TryLockMutex = int function(SDL_mutex* mutex); 47 alias pSDL_UnlockMutex = int function(SDL_mutex* mutex); 48 alias pSDL_DestroyMutex = void function(SDL_mutex* mutex); 49 alias pSDL_CreateSemaphore = SDL_sem* function(uint initial_value); 50 alias pSDL_DestroySemaphore = void function(SDL_sem* sem); 51 52 alias pSDL_SemWait = int function(SDL_sem* sem); 53 alias pSDL_SemWaitTimeout = int function(SDL_sem* sem, uint ms); 54 alias pSDL_SemPost = int function(SDL_sem* sem); 55 alias pSDL_SemValue = uint function(SDL_sem* sem); 56 57 alias pSDL_CreateCond = SDL_cond* function(); 58 alias pSDL_DestroyCond = void function(SDL_cond* cond); 59 alias pSDL_CondSignal = int function(SDL_cond* cond); 60 alias pSDL_CondBroadcast = int function(SDL_cond* cond); 61 alias pSDL_CondWait = int function(SDL_cond* cond,SDL_mutex*); 62 alias pSDL_CondWaitTimeout = int function(SDL_cond* cond, SDL_mutex* mutex, uint ms); 63 } 64 65 __gshared { 66 pSDL_CreateMutex SDL_CreateMutex; 67 pSDL_LockMutex SDL_LockMutex; 68 pSDL_TryLockMutex SDL_TryLockMutex; 69 pSDL_UnlockMutex SDL_UnlockMutex; 70 pSDL_DestroyMutex SDL_DestroyMutex; 71 pSDL_CreateSemaphore SDL_CreateSemaphore; 72 pSDL_DestroySemaphore SDL_DestroySemaphore; 73 pSDL_SemWait SDL_SemWait; 74 pSDL_SemWaitTimeout SDL_SemWaitTimeout; 75 pSDL_SemPost SDL_SemPost; 76 pSDL_SemValue SDL_SemValue; 77 pSDL_CreateCond SDL_CreateCond; 78 pSDL_DestroyCond SDL_DestroyCond; 79 pSDL_CondSignal SDL_CondSignal; 80 pSDL_CondBroadcast SDL_CondBroadcast; 81 pSDL_CondWait SDL_CondWait; 82 pSDL_CondWaitTimeout SDL_CondWaitTimeout; 83 } 84 }