include/SDL_mutex.h
changeset 337 9154ec9ca3d2
parent 297 f6ffac90895c
child 417 04ec6995f75d
equal deleted inserted replaced
336:745873ea091f 337:9154ec9ca3d2
    58 /* The SDL mutex structure, defined in SDL_mutex.c */
    58 /* The SDL mutex structure, defined in SDL_mutex.c */
    59 struct SDL_mutex;
    59 struct SDL_mutex;
    60 typedef struct SDL_mutex SDL_mutex;
    60 typedef struct SDL_mutex SDL_mutex;
    61 
    61 
    62 /* Create a mutex, initialized unlocked */
    62 /* Create a mutex, initialized unlocked */
    63 extern DECLSPEC SDL_mutex * SDL_CreateMutex(void);
    63 extern DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void);
    64 
    64 
    65 /* Lock the mutex  (Returns 0, or -1 on error) */
    65 /* Lock the mutex  (Returns 0, or -1 on error) */
    66 #define SDL_LockMutex(m)	SDL_mutexP(m)
    66 #define SDL_LockMutex(m)	SDL_mutexP(m)
    67 extern DECLSPEC int SDL_mutexP(SDL_mutex *mutex);
    67 extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex);
    68 
    68 
    69 /* Unlock the mutex  (Returns 0, or -1 on error) */
    69 /* Unlock the mutex  (Returns 0, or -1 on error) */
    70 #define SDL_UnlockMutex(m)	SDL_mutexV(m)
    70 #define SDL_UnlockMutex(m)	SDL_mutexV(m)
    71 extern DECLSPEC int SDL_mutexV(SDL_mutex *mutex);
    71 extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex);
    72 
    72 
    73 /* Destroy a mutex */
    73 /* Destroy a mutex */
    74 extern DECLSPEC void SDL_DestroyMutex(SDL_mutex *mutex);
    74 extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex);
    75 
    75 
    76 
    76 
    77 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    77 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    78 /* Semaphore functions                                           */
    78 /* Semaphore functions                                           */
    79 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    79 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    81 /* The SDL semaphore structure, defined in SDL_sem.c */
    81 /* The SDL semaphore structure, defined in SDL_sem.c */
    82 struct SDL_semaphore;
    82 struct SDL_semaphore;
    83 typedef struct SDL_semaphore SDL_sem;
    83 typedef struct SDL_semaphore SDL_sem;
    84 
    84 
    85 /* Create a semaphore, initialized with value, returns NULL on failure. */
    85 /* Create a semaphore, initialized with value, returns NULL on failure. */
    86 extern DECLSPEC SDL_sem * SDL_CreateSemaphore(Uint32 initial_value);
    86 extern DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
    87 
    87 
    88 /* Destroy a semaphore */
    88 /* Destroy a semaphore */
    89 extern DECLSPEC void SDL_DestroySemaphore(SDL_sem *sem);
    89 extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem);
    90 
    90 
    91 /* This function suspends the calling thread until the semaphore pointed 
    91 /* This function suspends the calling thread until the semaphore pointed 
    92  * to by sem has a positive count. It then atomically decreases the semaphore
    92  * to by sem has a positive count. It then atomically decreases the semaphore
    93  * count.
    93  * count.
    94  */
    94  */
    95 extern DECLSPEC int SDL_SemWait(SDL_sem *sem);
    95 extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem);
    96 
    96 
    97 /* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds,
    97 /* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds,
    98    SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error.
    98    SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error.
    99 */
    99 */
   100 extern DECLSPEC int SDL_SemTryWait(SDL_sem *sem);
   100 extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem);
   101 
   101 
   102 /* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if
   102 /* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if
   103    the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in
   103    the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in
   104    the allotted time, and -1 on error.
   104    the allotted time, and -1 on error.
   105    On some platforms this function is implemented by looping with a delay
   105    On some platforms this function is implemented by looping with a delay
   106    of 1 ms, and so should be avoided if possible.
   106    of 1 ms, and so should be avoided if possible.
   107 */
   107 */
   108 extern DECLSPEC int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms);
   108 extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms);
   109 
   109 
   110 /* Atomically increases the semaphore's count (not blocking), returns 0,
   110 /* Atomically increases the semaphore's count (not blocking), returns 0,
   111    or -1 on error.
   111    or -1 on error.
   112  */
   112  */
   113 extern DECLSPEC int SDL_SemPost(SDL_sem *sem);
   113 extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem);
   114 
   114 
   115 /* Returns the current count of the semaphore */
   115 /* Returns the current count of the semaphore */
   116 extern DECLSPEC Uint32 SDL_SemValue(SDL_sem *sem);
   116 extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem);
   117 
   117 
   118 
   118 
   119 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   119 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   120 /* Condition variable functions                                  */
   120 /* Condition variable functions                                  */
   121 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   121 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   123 /* The SDL condition variable structure, defined in SDL_cond.c */
   123 /* The SDL condition variable structure, defined in SDL_cond.c */
   124 struct SDL_cond;
   124 struct SDL_cond;
   125 typedef struct SDL_cond SDL_cond;
   125 typedef struct SDL_cond SDL_cond;
   126 
   126 
   127 /* Create a condition variable */
   127 /* Create a condition variable */
   128 extern DECLSPEC SDL_cond * SDL_CreateCond(void);
   128 extern DECLSPEC SDL_cond * SDLCALL SDL_CreateCond(void);
   129 
   129 
   130 /* Destroy a condition variable */
   130 /* Destroy a condition variable */
   131 extern DECLSPEC void SDL_DestroyCond(SDL_cond *cond);
   131 extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond);
   132 
   132 
   133 /* Restart one of the threads that are waiting on the condition variable,
   133 /* Restart one of the threads that are waiting on the condition variable,
   134    returns 0 or -1 on error.
   134    returns 0 or -1 on error.
   135  */
   135  */
   136 extern DECLSPEC int SDL_CondSignal(SDL_cond *cond);
   136 extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond);
   137 
   137 
   138 /* Restart all threads that are waiting on the condition variable,
   138 /* Restart all threads that are waiting on the condition variable,
   139    returns 0 or -1 on error.
   139    returns 0 or -1 on error.
   140  */
   140  */
   141 extern DECLSPEC int SDL_CondBroadcast(SDL_cond *cond);
   141 extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond);
   142 
   142 
   143 /* Wait on the condition variable, unlocking the provided mutex.
   143 /* Wait on the condition variable, unlocking the provided mutex.
   144    The mutex must be locked before entering this function!
   144    The mutex must be locked before entering this function!
   145    Returns 0 when it is signaled, or -1 on error.
   145    Returns 0 when it is signaled, or -1 on error.
   146  */
   146  */
   147 extern DECLSPEC int SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);
   147 extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);
   148 
   148 
   149 /* Waits for at most 'ms' milliseconds, and returns 0 if the condition
   149 /* Waits for at most 'ms' milliseconds, and returns 0 if the condition
   150    variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
   150    variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
   151    signaled in the allotted time, and -1 on error.
   151    signaled in the allotted time, and -1 on error.
   152    On some platforms this function is implemented by looping with a delay
   152    On some platforms this function is implemented by looping with a delay
   153    of 1 ms, and so should be avoided if possible.
   153    of 1 ms, and so should be avoided if possible.
   154 */
   154 */
   155 extern DECLSPEC int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms);
   155 extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms);
   156 
   156 
   157 /* Ends C function definitions when using C++ */
   157 /* Ends C function definitions when using C++ */
   158 #ifdef __cplusplus
   158 #ifdef __cplusplus
   159 }
   159 }
   160 #endif
   160 #endif