SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::RWLockRef Struct Reference

Handle to a non owned rWLock. More...

Inheritance diagram for SDL::RWLockRef:
Inheritance graph
[legend]

Public Member Functions

constexpr RWLockRef (const RWLockRef &other)
 Copy constructor.
 
constexpr RWLockRef (RWLockRef &&other)
 Move constructor.
 
constexpr ~RWLockRef ()=default
 Default constructor.
 
RWLockRefoperator= (RWLockRef other)
 Assignment operator.
 
void reset (SDL_RWLock *newResource={})
 Destroy a read/write lock created with RWLockBase.RWLockBase().
 
 RWLockBase ()
 Create a new read/write lock.
 
- Public Member Functions inherited from SDL::RWLockBase
 RWLockBase ()
 Create a new read/write lock.
 
void LockForReading ()
 Lock the read/write lock for read only operations.
 
void LockForWriting ()
 Lock the read/write lock for write operations.
 
void TryLockForReading ()
 Try to lock a read/write lock for reading without blocking.
 
void TryLockForWriting ()
 Try to lock a read/write lock for writing without blocking.
 
void Unlock ()
 Unlock the read/write lock.
 
constexpr Resource (T resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
- Public Member Functions inherited from SDL::Resource< SDL_RWLock * >
constexpr Resource (SDL_RWLock * resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other)=delete
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr bool operator== (const Resource &other) const=default
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr SDL_RWLock * get () const
 Return contained resource;.
 
constexpr SDL_RWLock * release (SDL_RWLock * newResource={})
 Return contained resource and empties or replace value.
 
constexpr const SDL_RWLock * operator-> () const
 Access to fields.
 
constexpr SDL_RWLock * operator-> ()
 Access to fields.
 

Detailed Description

Category:
Resource
See also
RWLockBase
RWLock

Member Function Documentation

◆ reset()

void SDL::RWLockRef::reset ( SDL_RWLock *  newResource = {})
inline

This function must be called on any read/write lock that is no longer needed. Failure to destroy a rwlock will result in a system memory or resource leak. While it is safe to destroy a rwlock that is unlocked, it is not safe to attempt to destroy a locked rwlock, and may result in undefined behavior depending on the platform.

Since
This function is available since SDL 3.2.0.
See also
RWLockBase.RWLockBase

◆ RWLockBase()

SDL::RWLockBase::RWLockBase ( )
inline

A read/write lock is useful for situations where you have multiple threads trying to access a resource that is rarely updated. All threads requesting a read-only lock will be allowed to run in parallel; if a thread requests a write lock, it will be provided exclusive access. This makes it safe for multiple threads to use a resource at the same time if they promise not to change it, and when it has to be changed, the rwlock will serve as a gateway to make sure those changes can be made safely.

In the right situation, a rwlock can be more efficient than a mutex, which only lets a single thread proceed at a time, even if it won't be modifying the data.

All newly-created read/write locks begin in the unlocked state.

Calls to RWLockBase.LockForReading() and RWLockBase.LockForWriting will not return while the rwlock is locked for writing by another thread. See RWLockBase.TryLockForReading() and RWLockBase.TryLockForWriting() to attempt to lock without blocking.

SDL read/write locks are only recursive for read-only locks! They are not guaranteed to be fair, or provide access in a FIFO manner! They are not guaranteed to favor writers. You may not lock a rwlock for both read-only and write access at the same time from the same thread (so you can't promote your read-only lock to a write lock without unlocking first).

Postcondition
the initialized and unlocked read/write lock or nullptr on failure; call GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
RWLockBase.LockForReading
RWLockBase.LockForWriting
RWLockBase.TryLockForReading
RWLockBase.TryLockForWriting
RWLockBase.Unlock

The documentation for this struct was generated from the following file: