DEADSOFTWARE

sdl: fix build on linux
[d2df-sdl.git] / src / lib / sdl2 / sdlmutex.inc
1 //from "sdl_mutex.h"
3 {**
4 * Synchronization functions which can time out return this value
5 * if they time out.
6 *}
7 const
8 SDL_MUTEX_TIMEDOUT = 1;
10 {**
11 * This is the timeout value which corresponds to never time out.
12 *}
13 //SDL_MUTEX_MAXWAIT (~(Uint32)0)
16 {**
17 * Mutex functions
18 *}
19 type
20 {* The SDL mutex structure, defined in SDL_mutex.c *}
21 PSDL_Mutex = Pointer; //todo!
23 {**
24 * Create a mutex, initialized unlocked.
25 *}
26 function SDL_CreateMutex: PSDL_Mutex cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateMutex' {$ENDIF} {$ENDIF};
28 {**
29 * Lock the mutex.
30 *
31 * 0, or -1 on error.
32 *}
33 //#define SDL_mutexP(m) SDL_LockMutex(m)
34 function SDL_LockMutex(mutex: PSDL_Mutex): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LockMutex' {$ENDIF} {$ENDIF};
36 {**
37 * Try to lock the mutex
38 *
39 * 0, SDL_MUTEX_TIMEDOUT, or -1 on error
40 *}
41 function SDL_TryLockMutex(mutex: PSDL_Mutex): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TryLockMutex' {$ENDIF} {$ENDIF};
43 {**
44 * Unlock the mutex.
45 *
46 * 0, or -1 on error.
47 *
48 * It is an error to unlock a mutex that has not been locked by
49 * the current thread, and doing so results in undefined behavior.
50 *}
51 //#define SDL_mutexV(m) SDL_UnlockMutex(m)
52 function SDL_UnlockMutex(mutex: PSDL_Mutex): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_UnlockMutex' {$ENDIF} {$ENDIF};
54 {**
55 * Destroy a mutex.
56 *}
57 procedure SDL_DestroyMutex(mutex: PSDL_Mutex) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DestroyMutex' {$ENDIF} {$ENDIF};
59 {*Mutex functions*}
61 {**
62 * Semaphore functions
63 *}
64 type
65 {* The SDL semaphore structure, defined in SDL_sem.c *}
66 PSDL_Sem = Pointer; //todo!
68 {**
69 * Create a semaphore, initialized with value, returns NULL on failure.
70 *}
71 function SDL_CreateSemaphore(initial_value: UInt32): PSDL_sem cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateSemaphore' {$ENDIF} {$ENDIF};
73 {**
74 * Destroy a semaphore.
75 *}
76 procedure SDL_DestroySemaphore(sem: PSDL_Sem) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DestroySemaphore' {$ENDIF} {$ENDIF};
78 {**
79 * This function suspends the calling thread until the semaphore pointed
80 * to by sem has a positive count. It then atomically decreases the
81 * semaphore count.
82 *}
83 function SDL_SemWait(sem: PSDL_Sem): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemWait' {$ENDIF} {$ENDIF};
85 {**
86 * Non-blocking variant of SDL_SemWait().
87 *
88 * 0 if the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait would
89 * block, and -1 on error.
90 *}
91 function SDL_SemTryWait(sem: PSDL_Sem): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemTryWait' {$ENDIF} {$ENDIF};
93 {**
94 * Variant of SDL_SemWait() with a timeout in milliseconds.
95 *
96 * 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait does not
97 * succeed in the allotted time, and -1 on error.
98 *
99 * On some platforms this function is implemented by looping with a
100 * delay of 1 ms, and so should be avoided if possible.
101 *}
102 function SDL_SemWaitTimeout(sem: PSDL_Sem; ms: UInt32): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemWaitTimeout' {$ENDIF} {$ENDIF};
104 {**
105 * Atomically increases the semaphore'_S count (not blocking).
107 * 0, or -1 on error.
108 *}
109 function SDL_SemPost(sem: PSDL_Sem): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemPost' {$ENDIF} {$ENDIF};
111 {**
112 * Returns the current count of the semaphore.
113 *}
114 function SDL_SemValue(sem: PSDL_Sem): UInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemValue' {$ENDIF} {$ENDIF};
116 {*Semaphore functions*}
118 {**
119 * Condition variable functions
120 * }
121 type
122 {* The SDL condition variable structure, defined in SDL_cond.c *}
123 PSDL_Cond = Pointer; //todo!!
125 {**
126 * Create a condition variable.
128 * Typical use of condition variables:
130 * Thread A:
131 * SDL_LockMutex(lock);
132 * while ( not condition )
133 * begin
134 * SDL_CondWait(cond, lock);
135 * end;
136 * SDL_UnlockMutex(lock);
138 * Thread B:
139 * SDL_LockMutex(lock);
140 * ...
141 * condition := true;
142 * ...
143 * SDL_CondSignal(cond);
144 * SDL_UnlockMutex(lock);
146 * There is some discussion whether to signal the condition variable
147 * with the mutex locked or not. There is some potential performance
148 * benefit to unlocking first on some platforms, but there are some
149 * potential race conditions depending on how your code is structured.
151 * In general it'_S safer to signal the condition variable while the
152 * mutex is locked.
153 *}
154 function SDL_CreateCond: PSDL_Cond cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateCond' {$ENDIF} {$ENDIF};
156 {**
157 * Destroy a condition variable.
158 *}
159 procedure SDL_DestroyCond(cond: PSDL_Cond) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DestroyCond' {$ENDIF} {$ENDIF};
161 {**
162 * Restart one of the threads that are waiting on the condition variable.
164 * 0 or -1 on error.
165 *}
166 function SDL_CondSignal(cond: PSDL_Cond): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CondSignal' {$ENDIF} {$ENDIF};
168 {**
169 * Restart all threads that are waiting on the condition variable.
171 * 0 or -1 on error.
172 *}
173 function SDL_CondBroadcast(cond: PSDL_Cond): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CondBroadcast' {$ENDIF} {$ENDIF};
175 {**
176 * Wait on the condition variable, unlocking the provided mutex.
178 * The mutex must be locked before entering this function!
180 * The mutex is re-locked once the condition variable is signaled.
182 * 0 when it is signaled, or -1 on error.
183 *}
184 function SDL_CondWait(cond: PSDL_Cond; mutex: PSDL_Mutex): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CondWait' {$ENDIF} {$ENDIF};
186 {**
187 * Waits for at most ms milliseconds, and returns 0 if the condition
188 * variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
189 * signaled in the allotted time, and -1 on error.
191 * On some platforms this function is implemented by looping with a
192 * delay of 1 ms, and so should be avoided if possible.
193 *}
194 function SDL_CondWaitTimeout(cond: PSDL_Cond; mutex: PSDL_Mutex; ms: UInt32): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CondWaitTimeout' {$ENDIF} {$ENDIF};