Cgu::Thread::RWLock::WriterLock Class Reference

A scoped locking class for exception safe RWLock write locking. More...

`#include <c++-gtk-utils/rw_lock.h>`

## Public Member Functions

| WriterLock (const RWLock::WriterLock &)=delete
RWLock::WriterLock & | operator= (const RWLock::WriterLock &)=delete
int | lock () noexcept
int | trylock () noexcept
int | unlock () noexcept
| WriterLock (RWLock &rw_lock_) noexcept
| WriterLock (RWLock &rw_lock_, Locked tag) noexcept
| WriterLock ()=delete
| ~WriterLock ()

## Detailed Description

A scoped locking class for exception safe RWLock write locking.

See Also
  Thread::RWLock Thread::RWLock::WriterTrackLock Thread::RWLock::ReaderLock Thread::RWLock::ReaderTrackLock Thread::Thread

## Constructor & Destructor Documentation

Cgu::Thread::RWLock::WriterLock::WriterLock | ( | const RWLock::WriterLock & | ) |  |

delete

This class cannot be copied. The copy constructor is deleted.

Cgu::Thread::RWLock::WriterLock::WriterLock | ( | RWLock & | rw_lock_) |  |

inlinenoexcept

This constructor locks for writing the read-write lock passed to it. It is not a cancellation point. It does not throw.

Parameters

  rw_lock_ | The read-write lock to be locked for writing.

Cgu::Thread::RWLock::WriterLock::WriterLock | ( | RWLock & | rw_lock_,
|  | Locked | tag
| ) |  |

inlinenoexcept

This constructor takes a read-write lock already locked for writing (say as a result of RWLock::writer_trylock()), and takes ownership of it. It is not a cancellation point. It does not throw.

Parameters

  rw_lock_ | The read-write lock to be managed for writing by this object.
  tag | Pass the Cgu::Thread::locked enum tag to this parameter.

Cgu::Thread::RWLock::WriterLock::WriterLock | ( | ) |  |

delete

This class requires initialisation with a RWLock. The default constructor is deleted.

Cgu::Thread::RWLock::WriterLock::~WriterLock | ( | ) |  |

inline

The destructor unlocks the owned read-write lock. It is not a cancellation point. It does not throw.

## Member Function Documentation

int Cgu::Thread::RWLock::WriterLock::lock | ( | ) |  |

inlinenoexcept

Calls RWLock::writer_lock(), and so locks the read-write lock for writing and reacquires ownership. It blocks if the read-write lock is already locked for reading or writing until it becomes free. This method should normally only be called if a previous call has been made to RWLock::WriterLock::unlock() (that is, where the thread owning the RWLock::WriterLock object has temporarily allowed another thread to take the read-write lock concerned for reading or writing). It is not a cancellation point. It does not throw.

Returns
  0 if successful, otherwise the pthread read-write lock error number.

Note
  With this library implementation, the only pthread error number which could be returned by this method is EDEADLK, which it would do if the default pthread reader lock behaviour happens to return that error rather than deadlock where the thread calling this method already holds a read lock or write lock on the particular read-write lock in question. Most default implementations do not do this (they just deadlock) and hence the return value is usually not worth checking for except during debugging.

See Also
  RWLock::WriterTrackLock

RWLock::WriterLock& Cgu::Thread::RWLock::WriterLock::operator= | ( | const RWLock::WriterLock & | ) |  |

delete

This class cannot be copied. The assignment operator is deleted.

int Cgu::Thread::RWLock::WriterLock::trylock | ( | ) |  |

inlinenoexcept

Calls RWLock::writer_trylock(), and so tries to lock the read-write lock for writing and reacquire ownership, but returns immediately with value EBUSY if it is already locked for reading or writing. This method should normally only be called if a previous call has been made to RWLock::WriterLock::unlock() (that is, where the thread owning the RWLock::WriterLock object has temporarily allowed another thread to take the read-write lock concerned for reading or writing). It is not a cancellation point. It does not throw.

Returns
  0 if successful, otherwise EBUSY.

Note
  With this library implementation, the only pthread error number which could be returned by this method is EBUSY.

See Also
  RWLock::WriterTrackLock

int Cgu::Thread::RWLock::WriterLock::unlock | ( | ) |  |

inlinenoexcept

Calls RWLock::unlock(), and so unlocks a locked read-write lock owned by the calling thread for writing and relinquishes ownership (so temporarily allowing another thread to take the read-write lock). This method should normally only be called if it is to be followed by a call to RWLock::WriterLock::lock() or a successful call to RWLock::WriterLock::trylock() before the RWLock::WriterLock object concerned goes out of scope (otherwise RWLock::WriterLock's destructor will attempt to unlock an already unlocked read-write lock or a read-write lock of which another thread has by then taken ownership - RWLock::WriterLock objects do not maintain state). See RWLock::WriterTrackLock::unlock() for a safe version of this method. It is not a cancellation point. It does not throw.

Returns
  0 if successful, otherwise the pthread read-write lock error number.

Note
  With this library implementation, the only pthread error number which could be returned by this method is EPERM because the calling thread does hold a lock on the particular read-write lock in question (however POSIX does not require that return value in that case and hence the return value is usually not worth checking for except during debugging).

See Also
  RWLock::WriterTrackLock

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

- rw_lock.h