4 * Synchronization functions which can time out return this value
8 SDL_MUTEX_TIMEDOUT = 1;
11 * This is the timeout value which corresponds to never time out.
13 //SDL_MUTEX_MAXWAIT (~(Uint32)0)
20 {* The SDL mutex structure, defined in SDL_mutex.c *}
21 PSDL_Mutex = Pointer; //todo!
24 * Create a mutex, initialized unlocked.
26 function SDL_CreateMutex: PSDL_Mutex cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateMutex' {$ENDIF} {$ENDIF};
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};
37 * Try to lock the mutex
39 * 0, SDL_MUTEX_TIMEDOUT, or -1 on error
41 function SDL_TryLockMutex(mutex: PSDL_Mutex): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TryLockMutex' {$ENDIF} {$ENDIF};
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.
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};
57 procedure SDL_DestroyMutex(mutex: PSDL_Mutex) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DestroyMutex' {$ENDIF} {$ENDIF};
65 {* The SDL semaphore structure, defined in SDL_sem.c *}
66 PSDL_Sem = Pointer; //todo!
69 * Create a semaphore, initialized with value, returns NULL on failure.
71 function SDL_CreateSemaphore(initial_value: UInt32): PSDL_sem cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateSemaphore' {$ENDIF} {$ENDIF};
74 * Destroy a semaphore.
76 procedure SDL_DestroySemaphore(sem: PSDL_Sem) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DestroySemaphore' {$ENDIF} {$ENDIF};
79 * This function suspends the calling thread until the semaphore pointed
80 * to by sem has a positive count. It then atomically decreases the
83 function SDL_SemWait(sem: PSDL_Sem): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemWait' {$ENDIF} {$ENDIF};
86 * Non-blocking variant of SDL_SemWait().
88 * 0 if the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait would
89 * block, and -1 on error.
91 function SDL_SemTryWait(sem: PSDL_Sem): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemTryWait' {$ENDIF} {$ENDIF};
94 * Variant of SDL_SemWait() with a timeout in milliseconds.
96 * 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait does not
97 * succeed in the allotted time, and -1 on error.
99 * On some platforms this function is implemented by looping with a
100 * delay of 1 ms, and so should be avoided if possible.
102 function SDL_SemWaitTimeout(sem: PSDL_Sem; ms: UInt32): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemWaitTimeout' {$ENDIF} {$ENDIF};
105 * Atomically increases the semaphore'_S count (not blocking).
109 function SDL_SemPost(sem: PSDL_Sem): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemPost' {$ENDIF} {$ENDIF};
112 * Returns the current count of the semaphore.
114 function SDL_SemValue(sem: PSDL_Sem): UInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SemValue' {$ENDIF} {$ENDIF};
116 {*Semaphore functions*}
119 * Condition variable functions
122 {* The SDL condition variable structure, defined in SDL_cond.c *}
123 PSDL_Cond = Pointer; //todo!!
126 * Create a condition variable.
128 * Typical use of condition variables:
131 * SDL_LockMutex(lock);
132 * while ( not condition )
134 * SDL_CondWait(cond, lock);
136 * SDL_UnlockMutex(lock);
139 * SDL_LockMutex(lock);
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
154 function SDL_CreateCond: PSDL_Cond cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CreateCond' {$ENDIF} {$ENDIF};
157 * Destroy a condition variable.
159 procedure SDL_DestroyCond(cond: PSDL_Cond) cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DestroyCond' {$ENDIF} {$ENDIF};
162 * Restart one of the threads that are waiting on the condition variable.
166 function SDL_CondSignal(cond: PSDL_Cond): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CondSignal' {$ENDIF} {$ENDIF};
169 * Restart all threads that are waiting on the condition variable.
173 function SDL_CondBroadcast(cond: PSDL_Cond): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CondBroadcast' {$ENDIF} {$ENDIF};
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.
184 function SDL_CondWait(cond: PSDL_Cond; mutex: PSDL_Mutex): SInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_CondWait' {$ENDIF} {$ENDIF};
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.
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};