carb::input::ScopedWrite

Defined in carb/input/IInput.h

class ScopedWrite

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

Public Functions

inline ScopedWrite(IInput *iface, ActionMappingSetHandle set)

Constructor.

Once constructed, a write lock is held until *this is destroyed. Locks are recursive. Write locks should be held across any IInput functions that take a non-const ActionMappingSet handle, but may also be held across read-only functions as well (functions that take a const ActionMappingSet handle).

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 ~ScopedWrite()

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 ScopedWrite(ScopedWrite &&other)

Move constructor; moves a lock from another ScopedWrite object.

Warning

It is undefined behavior to cause the moved ScopedWrite 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 ScopedWrite &operator=(ScopedWrite &&other)

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

Warning

It is undefined behavior to cause the moved ScopedWrite 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.