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

Reference for RWLock. More...

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

Public Member Functions

constexpr RWLockRef (RWLockRaw resource) noexcept
 Constructs from raw RWLock. More...
 
constexpr RWLockRef (const RWLock &resource) noexcept
 Constructs from RWLock. More...
 
constexpr RWLockRef (RWLock &&resource) noexcept
 Constructs from RWLock. More...
 
constexpr RWLockRef (const RWLockRef &other) noexcept
 Copy constructor.
 
constexpr RWLockRef (RWLockRef &&other) noexcept
 Move constructor.
 
 ~RWLockRef ()
 Destructor.
 
RWLockRefoperator= (const RWLockRef &other) noexcept
 Assignment operator.
 
constexpr operator RWLockRaw () const noexcept
 Converts to RWLockRaw.
 
constexpr RWLock (std::nullptr_t) noexcept
 Default ctor.
 
constexpr RWLock (RWLockRaw resource) noexcept
 Constructs from raw RWLock. More...
 
constexpr RWLock (const RWLock &other) noexcept=delete
 Copy constructor.
 
constexpr RWLock (RWLock &&other) noexcept
 Move constructor.
 
constexpr RWLock (const RWLockRef &other)=delete
 
constexpr RWLock (RWLockRef &&other)=delete
 
 RWLock ()
 Create a new read/write lock. More...
 
- Public Member Functions inherited from SDL::RWLock
constexpr RWLock (std::nullptr_t) noexcept
 Default ctor.
 
constexpr RWLock (RWLockRaw resource) noexcept
 Constructs from raw RWLock. More...
 
constexpr RWLock (const RWLock &other) noexcept=delete
 Copy constructor.
 
constexpr RWLock (RWLock &&other) noexcept
 Move constructor.
 
constexpr RWLock (const RWLockRef &other)=delete
 
constexpr RWLock (RWLockRef &&other)=delete
 
 RWLock ()
 Create a new read/write lock. More...
 
 ~RWLock ()
 Destructor.
 
constexpr RWLockoperator= (RWLock &&other) noexcept
 Assignment operator.
 
RWLockoperator= (const RWLock &other)=delete
 Assignment operator.
 
constexpr RWLockRaw get () const noexcept
 Retrieves underlying RWLockRaw.
 
constexpr RWLockRaw release () noexcept
 Retrieves underlying RWLockRaw and clear this.
 
constexpr auto operator<=> (const RWLock &other) const noexcept=default
 Comparison.
 
constexpr operator bool () const noexcept
 Converts to bool.
 
void Destroy ()
 Destroy a read/write lock created with CreateRWLock(). More...
 
void LockForReading ()
 Lock the read/write lock for read only operations. More...
 
void LockForWriting ()
 Lock the read/write lock for write operations. More...
 
bool TryLockForReading ()
 Try to lock a read/write lock for reading without blocking. More...
 
bool TryLockForWriting ()
 Try to lock a read/write lock for writing without blocking. More...
 
void Unlock ()
 Unlock the read/write lock. More...
 

Detailed Description

This does not take ownership!

Constructor & Destructor Documentation

◆ RWLockRef() [1/3]

constexpr SDL::RWLockRef::RWLockRef ( RWLockRaw  resource)
inlineconstexprnoexcept
Parameters
resourcea RWLockRaw.

This does not takes ownership!

◆ RWLockRef() [2/3]

constexpr SDL::RWLockRef::RWLockRef ( const RWLock resource)
inlineconstexprnoexcept
Parameters
resourcea RWLock.

This does not takes ownership!

◆ RWLockRef() [3/3]

constexpr SDL::RWLockRef::RWLockRef ( RWLock &&  resource)
inlineconstexprnoexcept
Parameters
resourcea RWLock.

This will release the ownership from resource!

Member Function Documentation

◆ RWLock() [1/2]

SDL::RWLock::RWLock ( )
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 LockRWLockForReading() and LockRWLockForWriting will not return while the rwlock is locked for writing by another thread. See RWLock.TryLockForReading() and RWLock.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.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
RWLock.Destroy
LockRWLockForReading
LockRWLockForWriting
RWLock.TryLockForReading
RWLock.TryLockForWriting
RWLock.Unlock

◆ RWLock() [2/2]

constexpr SDL::RWLock::RWLock ( RWLockRaw  resource)
inlineexplicitconstexprnoexcept
Parameters
resourcea RWLockRaw to be wrapped.

This assumes the ownership, call release() if you need to take back.


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