sdlTryLockMutex function mutex

bool sdlTryLockMutex(
  1. Pointer<SdlMutex> mutex
)

Try to lock a mutex without blocking.

This works just like SDL_LockMutex(), but if the mutex is not available, this function returns false immediately.

This technique is useful if you need exclusive access to a resource but don't want to wait for it, and will return to it to try again later.

This function returns true if passed a NULL mutex.

\param mutex the mutex to try to lock. \returns true on success, false if the mutex would block.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.2.0.

\sa SDL_LockMutex \sa SDL_UnlockMutex

extern SDL_DECLSPEC bool SDLCALL SDL_TryLockMutex(SDL_Mutex *mutex) SDL_TRY_ACQUIRE(true, mutex)

Implementation

bool sdlTryLockMutex(Pointer<SdlMutex> mutex) {
  final sdlTryLockMutexLookupFunction = _libSdl
      .lookupFunction<
        Uint8 Function(Pointer<SdlMutex> mutex),
        int Function(Pointer<SdlMutex> mutex)
      >('SDL_TryLockMutex');
  return sdlTryLockMutexLookupFunction(mutex) == 1;
}