carb::input::ScopedRead

Defined in carb/input/IInput.h

class ScopedRead

A RAII class for holding a read lock over multiple operations.

Public Functions

inline ScopedRead(IInput *iface, const ActionMappingSetHandle set)

Constructor.

Once constructed, a read lock is held until *this is destroyed. Locks are recursive. Read locks should be held for IInput functions that take a const ActionMappingSet.

Warning

It is possible to take a ScopedWrite lock after a ScopedRead lock. However, in this situation all locks are temporarily removed while an exclusive lock is obtained. The state of the object is therefore allowed to change immediately prior to taking the ScopedWrite. To minimize this occurrence, operations which may require a write lock should take a speculative ScopedWrite instead of ScopedRead followed by a later ScopedWrite.

Parameters
  • iface – The IInput interface to use.

  • set – The ActionMappingSet handle to hold the lock on.

inline ~ScopedRead()

Destructor; releases the lock.

Warning

It is undefined behavior to allow *this to be destroyed by a different thread than the one that created it.

inline ScopedRead(ScopedRead &&other)

Move constructor; moves a lock from another ScopedRead object.

Warning

It is undefined behavior to cause the moved ScopedRead to be destroyed by a different thread than the one that created it.

Parameters

other – The lock to move from. Will be left in a valid but inactive state.

inline ScopedRead &operator=(ScopedRead &&other)

Move-assign operator; moves a lock from another ScopedRead object.

Warning

It is undefined behavior to cause the moved ScopedRead to be destroyed by a different thread than the one that created it.

Parameters

other – The lock to move from. Effectively swapped with *this.

Returns

*this.