c++-gtk-utils

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
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

## ◆ WriterLock() [1/4]

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

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

## ◆ WriterLock() [2/4]

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

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.

## ◆ WriterLock() [3/4]

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

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.

## ◆ WriterLock() [4/4]

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

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

## ◆ ~WriterLock()

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

## ◆ lock()

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

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

## ◆ operator=()

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

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

## ◆ trylock()

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

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

## ◆ unlock()

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

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