Convert ticks to 64-bit, added nanosecond precision to the API
Fixes https://github.com/libsdl-org/SDL/issues/5512 Fixes https://github.com/libsdl-org/SDL/issues/6731
This commit is contained in:
@@ -46,7 +46,7 @@ extern "C" {
|
||||
/**
|
||||
* This is the timeout value which corresponds to never time out.
|
||||
*/
|
||||
#define SDL_MUTEX_MAXWAIT (~(Uint32)0)
|
||||
#define SDL_MUTEX_MAXWAIT -1
|
||||
|
||||
|
||||
/**
|
||||
@@ -194,6 +194,7 @@ typedef struct SDL_semaphore SDL_sem;
|
||||
* \sa SDL_SemValue
|
||||
* \sa SDL_SemWait
|
||||
* \sa SDL_SemWaitTimeout
|
||||
* \sa SDL_SemWaitTimeoutNS
|
||||
*/
|
||||
extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
|
||||
|
||||
@@ -213,8 +214,9 @@ extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
|
||||
* \sa SDL_SemValue
|
||||
* \sa SDL_SemWait
|
||||
* \sa SDL_SemWaitTimeout
|
||||
* \sa SDL_SemWaitTimeoutNS
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
|
||||
extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem);
|
||||
|
||||
/**
|
||||
* Wait until a semaphore has a positive value and then decrements it.
|
||||
@@ -240,8 +242,9 @@ extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
|
||||
* \sa SDL_SemValue
|
||||
* \sa SDL_SemWait
|
||||
* \sa SDL_SemWaitTimeout
|
||||
* \sa SDL_SemWaitTimeoutNS
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
|
||||
extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem);
|
||||
|
||||
/**
|
||||
* See if a semaphore has a positive value and decrement it if it does.
|
||||
@@ -264,8 +267,9 @@ extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
|
||||
* \sa SDL_SemValue
|
||||
* \sa SDL_SemWait
|
||||
* \sa SDL_SemWaitTimeout
|
||||
* \sa SDL_SemWaitTimeoutNS
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
|
||||
extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem);
|
||||
|
||||
/**
|
||||
* Wait until a semaphore has a positive value and then decrements it.
|
||||
@@ -276,7 +280,7 @@ extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
|
||||
* successful it will atomically decrement the semaphore value.
|
||||
*
|
||||
* \param sem the semaphore to wait on
|
||||
* \param timeout the length of the timeout, in milliseconds
|
||||
* \param timeoutMS the length of the timeout, in milliseconds
|
||||
* \returns 0 if the wait succeeds, `SDL_MUTEX_TIMEDOUT` if the wait does not
|
||||
* succeed in the allotted time, or a negative error code on failure;
|
||||
* call SDL_GetError() for more information.
|
||||
@@ -289,8 +293,35 @@ extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
|
||||
* \sa SDL_SemTryWait
|
||||
* \sa SDL_SemValue
|
||||
* \sa SDL_SemWait
|
||||
* \sa SDL_SemWaitTimeoutNS
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout);
|
||||
extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Sint32 timeoutMS);
|
||||
|
||||
/**
|
||||
* Wait until a semaphore has a positive value and then decrements it.
|
||||
*
|
||||
* This function suspends the calling thread until either the semaphore
|
||||
* pointed to by `sem` has a positive value, the call is interrupted by a
|
||||
* signal or error, or the specified time has elapsed. If the call is
|
||||
* successful it will atomically decrement the semaphore value.
|
||||
*
|
||||
* \param sem the semaphore to wait on
|
||||
* \param timeoutNS the length of the timeout, in nanoseconds
|
||||
* \returns 0 if the wait succeeds, `SDL_MUTEX_TIMEDOUT` if the wait does not
|
||||
* succeed in the allotted time, or a negative error code on failure;
|
||||
* call SDL_GetError() for more information.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_CreateSemaphore
|
||||
* \sa SDL_DestroySemaphore
|
||||
* \sa SDL_SemPost
|
||||
* \sa SDL_SemTryWait
|
||||
* \sa SDL_SemValue
|
||||
* \sa SDL_SemWait
|
||||
* \sa SDL_SemWaitTimeout
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemWaitTimeoutNS(SDL_sem *sem, Sint64 timeoutNS);
|
||||
|
||||
/**
|
||||
* Atomically increment a semaphore's value and wake waiting threads.
|
||||
@@ -308,7 +339,7 @@ extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout);
|
||||
* \sa SDL_SemWait
|
||||
* \sa SDL_SemWaitTimeout
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
|
||||
extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem);
|
||||
|
||||
/**
|
||||
* Get the current value of a semaphore.
|
||||
@@ -320,7 +351,7 @@ extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
|
||||
*
|
||||
* \sa SDL_CreateSemaphore
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem * sem);
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem);
|
||||
|
||||
/* @} *//* Semaphore functions */
|
||||
|
||||
@@ -346,6 +377,7 @@ typedef struct SDL_cond SDL_cond;
|
||||
* \sa SDL_CondSignal
|
||||
* \sa SDL_CondWait
|
||||
* \sa SDL_CondWaitTimeout
|
||||
* \sa SDL_CondWaitTimeoutNS
|
||||
* \sa SDL_DestroyCond
|
||||
*/
|
||||
extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
|
||||
@@ -361,9 +393,10 @@ extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
|
||||
* \sa SDL_CondSignal
|
||||
* \sa SDL_CondWait
|
||||
* \sa SDL_CondWaitTimeout
|
||||
* \sa SDL_CondWaitTimeoutNS
|
||||
* \sa SDL_CreateCond
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
|
||||
extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond);
|
||||
|
||||
/**
|
||||
* Restart one of the threads that are waiting on the condition variable.
|
||||
@@ -377,10 +410,11 @@ extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
|
||||
* \sa SDL_CondBroadcast
|
||||
* \sa SDL_CondWait
|
||||
* \sa SDL_CondWaitTimeout
|
||||
* \sa SDL_CondWaitTimeoutNS
|
||||
* \sa SDL_CreateCond
|
||||
* \sa SDL_DestroyCond
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
|
||||
extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond);
|
||||
|
||||
/**
|
||||
* Restart all threads that are waiting on the condition variable.
|
||||
@@ -394,10 +428,11 @@ extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
|
||||
* \sa SDL_CondSignal
|
||||
* \sa SDL_CondWait
|
||||
* \sa SDL_CondWaitTimeout
|
||||
* \sa SDL_CondWaitTimeoutNS
|
||||
* \sa SDL_CreateCond
|
||||
* \sa SDL_DestroyCond
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
|
||||
extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond);
|
||||
|
||||
/**
|
||||
* Wait until a condition variable is signaled.
|
||||
@@ -422,10 +457,11 @@ extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
|
||||
* \sa SDL_CondBroadcast
|
||||
* \sa SDL_CondSignal
|
||||
* \sa SDL_CondWaitTimeout
|
||||
* \sa SDL_CondWaitTimeoutNS
|
||||
* \sa SDL_CreateCond
|
||||
* \sa SDL_DestroyCond
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex);
|
||||
extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex);
|
||||
|
||||
/**
|
||||
* Wait until a condition variable is signaled or a certain time has passed.
|
||||
@@ -440,7 +476,7 @@ extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex);
|
||||
*
|
||||
* \param cond the condition variable to wait on
|
||||
* \param mutex the mutex used to coordinate thread access
|
||||
* \param ms the maximum time to wait, in milliseconds, or `SDL_MUTEX_MAXWAIT`
|
||||
* \param timeoutMS the maximum time to wait, in milliseconds, or `SDL_MUTEX_MAXWAIT`
|
||||
* to wait indefinitely
|
||||
* \returns 0 if the condition variable is signaled, `SDL_MUTEX_TIMEDOUT` if
|
||||
* the condition is not signaled in the allotted time, or a negative
|
||||
@@ -451,11 +487,42 @@ extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex);
|
||||
* \sa SDL_CondBroadcast
|
||||
* \sa SDL_CondSignal
|
||||
* \sa SDL_CondWait
|
||||
* \sa SDL_CondWaitTimeoutNS
|
||||
* \sa SDL_CreateCond
|
||||
* \sa SDL_DestroyCond
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond * cond,
|
||||
SDL_mutex * mutex, Uint32 ms);
|
||||
extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond,
|
||||
SDL_mutex *mutex, Sint32 timeoutMS);
|
||||
|
||||
/**
|
||||
* Wait until a condition variable is signaled or a certain time has passed.
|
||||
*
|
||||
* This function unlocks the specified `mutex` and waits for another thread to
|
||||
* call SDL_CondSignal() or SDL_CondBroadcast() on the condition variable
|
||||
* `cond`, or for the specified time to elapse. Once the condition variable is
|
||||
* signaled or the time elapsed, the mutex is re-locked and the function
|
||||
* returns.
|
||||
*
|
||||
* The mutex must be locked before calling this function.
|
||||
*
|
||||
* \param cond the condition variable to wait on
|
||||
* \param mutex the mutex used to coordinate thread access
|
||||
* \param timeoutNS the maximum time to wait, in nanoseconds, or `SDL_MUTEX_MAXWAIT` to wait indefinitely
|
||||
* \returns 0 if the condition variable is signaled, `SDL_MUTEX_TIMEDOUT` if
|
||||
* the condition is not signaled in the allotted time, or a negative
|
||||
* error code on failure; call SDL_GetError() for more information.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_CondBroadcast
|
||||
* \sa SDL_CondSignal
|
||||
* \sa SDL_CondWait
|
||||
* \sa SDL_CondWaitTimeout
|
||||
* \sa SDL_CreateCond
|
||||
* \sa SDL_DestroyCond
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_CondWaitTimeoutNS(SDL_cond *cond,
|
||||
SDL_mutex *mutex, Sint64 timeoutNS);
|
||||
|
||||
/* @} *//* Condition variable functions */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user