sdlTryLockRwLockForWriting function mutex

bool sdlTryLockRwLockForWriting(
  1. Pointer<SdlRwLock> rwlock
)

Try to lock a read/write lock for writing without blocking.

This works just like SDL_LockRWLockForWriting(), but if the rwlock is not available, then 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.

It is illegal for the owning thread to lock an already-locked rwlock for writing (read-only may be locked recursively, writing can not). Doing so results in undefined behavior.

It is illegal to request a write lock from a thread that already holds a read-only lock. Doing so results in undefined behavior. Unlock the read-only lock before requesting a write lock.

This function returns true if passed a NULL rwlock.

\param rwlock the rwlock to try to lock. \returns true on success, false if the lock 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_LockRWLockForWriting \sa SDL_TryLockRWLockForReading \sa SDL_UnlockRWLock

extern SDL_DECLSPEC bool SDLCALL SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE(true, rwlock)

Implementation

bool sdlTryLockRwLockForWriting(Pointer<SdlRwLock> rwlock) {
  final sdlTryLockRwLockForWritingLookupFunction = _libSdl
      .lookupFunction<
        Uint8 Function(Pointer<SdlRwLock> rwlock),
        int Function(Pointer<SdlRwLock> rwlock)
      >('SDL_TryLockRWLockForWriting');
  return sdlTryLockRwLockForWritingLookupFunction(rwlock) == 1;
}