SDL_ExitProcess() was ignoring exit code parameter.
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
28 * Functions to provide thread synchronization primitives.
31 #include "SDL_stdinc.h"
32 #include "SDL_error.h"
34 #include "begin_code.h"
35 /* Set up for C function definitions, even when using C++ */
43 * Synchronization functions which can time out return this value
46 #define SDL_MUTEX_TIMEDOUT 1
49 * This is the timeout value which corresponds to never time out.
51 #define SDL_MUTEX_MAXWAIT (~(Uint32)0)
55 * \name Mutex functions
59 /* The SDL mutex structure, defined in SDL_mutex.c */
61 typedef struct SDL_mutex SDL_mutex;
64 * Create a mutex, initialized unlocked.
66 extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void);
71 * \return 0, or -1 on error.
73 #define SDL_LockMutex(m) SDL_mutexP(m)
74 extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex);
79 * \return 0, or -1 on error.
81 * \warning It is an error to unlock a mutex that has not been locked by
82 * the current thread, and doing so results in undefined behavior.
84 #define SDL_UnlockMutex(m) SDL_mutexV(m)
85 extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex);
90 extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex * mutex);
92 /*@}*//*Mutex functions*/
96 * \name Semaphore functions
100 /* The SDL semaphore structure, defined in SDL_sem.c */
101 struct SDL_semaphore;
102 typedef struct SDL_semaphore SDL_sem;
105 * Create a semaphore, initialized with value, returns NULL on failure.
107 extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
110 * Destroy a semaphore.
112 extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
115 * This function suspends the calling thread until the semaphore pointed
116 * to by \c sem has a positive count. It then atomically decreases the
119 extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
122 * Non-blocking variant of SDL_SemWait().
124 * \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait would
125 * block, and -1 on error.
127 extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
130 * Variant of SDL_SemWait() with a timeout in milliseconds.
132 * \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait does not
133 * succeed in the allotted time, and -1 on error.
135 * \warning On some platforms this function is implemented by looping with a
136 * delay of 1 ms, and so should be avoided if possible.
138 extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem * sem, Uint32 ms);
141 * Atomically increases the semaphore's count (not blocking).
143 * \return 0, or -1 on error.
145 extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
148 * Returns the current count of the semaphore.
150 extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem * sem);
152 /*@}*//*Semaphore functions*/
156 * \name Condition variable functions
160 /* The SDL condition variable structure, defined in SDL_cond.c */
162 typedef struct SDL_cond SDL_cond;
165 * Create a condition variable.
167 * Typical use of condition variables:
170 * SDL_LockMutex(lock);
171 * while ( ! condition ) {
172 * SDL_CondWait(cond, lock);
174 * SDL_UnlockMutex(lock);
177 * SDL_LockMutex(lock);
181 * SDL_CondSignal(cond);
182 * SDL_UnlockMutex(lock);
184 * There is some discussion whether to signal the condition variable
185 * with the mutex locked or not. There is some potential performance
186 * benefit to unlocking first on some platforms, but there are some
187 * potential race conditions depending on how your code is structured.
189 * In general it's safer to signal the condition variable while the
192 extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
195 * Destroy a condition variable.
197 extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
200 * Restart one of the threads that are waiting on the condition variable.
202 * \return 0 or -1 on error.
204 extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
207 * Restart all threads that are waiting on the condition variable.
209 * \return 0 or -1 on error.
211 extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
214 * Wait on the condition variable, unlocking the provided mutex.
216 * \warning The mutex must be locked before entering this function!
218 * The mutex is re-locked once the condition variable is signaled.
220 * \return 0 when it is signaled, or -1 on error.
222 extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex);
225 * Waits for at most \c ms milliseconds, and returns 0 if the condition
226 * variable is signaled, ::SDL_MUTEX_TIMEDOUT if the condition is not
227 * signaled in the allotted time, and -1 on error.
229 * \warning On some platforms this function is implemented by looping with a
230 * delay of 1 ms, and so should be avoided if possible.
232 extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond * cond,
233 SDL_mutex * mutex, Uint32 ms);
235 /*@}*//*Condition variable functions*/
238 /* Ends C function definitions when using C++ */
244 #include "close_code.h"
246 #endif /* _SDL_mutex_h */
248 /* vi: set ts=4 sw=4 expandtab: */