Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Inti::G::StaticRecMutex Struct Reference

A compile-time GStaticRecMutex C++ wrapper interface. More...

`#include <inti/glib/mutex.h>`

Inheritance diagram for Inti::G::StaticRecMutex:

List of all members.

## Public Member Functions

Constructors

- void init ()
    Initializes a StaticRecMutex. Alternatively you can initialize it with G::INTI_STATIC_REC_MUTEX_INIT.

Accessors

- GStaticRecMutex * g_static_rec_mutex () const
    Get a pointer to the GStaticRecMutex object.
- operator GStaticRecMutex * () const
    Conversion operator; Safely converts a G::StaticRecMutex object into a GStaticRecMutex pointer.
- bool is_locked () const
    Returns true it the mutex is locked, that is, if its locked depth one or more.

Methods

- void lock (unsigned int depth=1)
    Locks the mutex.
- bool trylock ()
    Tries to lock the mutex.
- void unlock ()
    Unlocks the mutex one level.
- unsigned int unlock_full ()
    Unlocks the mutex completely.

## Detailed Description

A compile-time GStaticRecMutex C++ wrapper interface.

A StaticRecMutex works like a StaticMutex, but it can be locked multiple times by one thread If you enter it n times, however, you have to unlock it n times again to let other threads lock it. An exception is the function unlock_full(), that allows you to unlock a StaticRecMutex completely returning the depth, i.e. the number of times this mutex was locked. The depth can later be used to restore the state by calling lock().

A StaticRecMutex can be statically initialized with the value INTI_STATIC_REC_MUTEX_INIT. All of the StaticRecMutex methods can be used if G::Thread::init() has not been called.

## Member Function Documentation

void Inti::G::StaticRecMutex::lock | ( | unsigned int | depth = 1 | ) |

  | Locks the mutex. Parameters:
  depth | The number of times the mutex has to be unlocked to be completely unlocked.
If the mutex is already locked by another thread, the current thread will block until mutex is unlocked by the other thread. If mutex is already locked by the calling thread, this functions increases the depth of mutex depth times and returns. The default depth is one.

bool Inti::G::StaticRecMutex::trylock | ( |  | ) |

| Tries to lock the mutex. Returns: true if the mutex could be locked. If mutex is already locked by another thread, it immediately returns false. Otherwise it locks mutex and returns true. If mutex is already locked by the calling thread, this functions increases the depth of mutex by one and immediately returns true.

void Inti::G::StaticRecMutex::unlock | ( |  | ) |

| Unlocks the mutex one level. Other threads can only lock the mutex when it has been unlocked as many times, as it had been locked before. If mutex is completely unlocked and another thread is blocked in a lock() call for mutex, it will be woken and can lock mutex itself.

unsigned int Inti::G::StaticRecMutex::unlock_full | ( |  | ) |

| Unlocks the mutex completely. Other threads can only lock mutex when it has been unlocked as many times, as it had been locked before. If mutex is completely unlocked and another thread is blocked in a lock() call for mutex, it will be woken and can lock mutex itself.

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

- mutex.h

Main Page - Footer