Include the header "Dinkum/threads/mutex"
to define the non-recursive mutex
classes mutex, try_mutex and timed_mutex.
namespace Dinkum {
namespace threads {
class mutex;
class try_mutex;
class timed_mutex;
} // namespace threads
} // namespace Dinkum
mutexclass mutex
{
public:
mutex();
~mutex();
typedef SL0 scoped_lock;
// exposition only
private:
// not implemented
mutex(const mutex&);
mutex& operator= (const mutex&);
};
The class describes an object that
can be used with a scoped lock
to provide a non-recursive mutex.
Objects of class mutex cannot be copied.
mutex::mutexmutex();
The constructor constructs a mutex in the unlocked state.
mutex::~mutex~mutex();
Precondition: the object must not be locked.
The destructor releases any resources used by the object.
try_mutexclass try_mutex
{
public:
try_mutex();
~try_mutex();
typedef SL0 scoped_lock;
typedef SL1 scoped_try_lock;
// exposition only
private:
// not implemented
try_mutex(const try_mutex&);
try_mutex& operator= (const try_mutex&);
};
The class describes an object that
can be used with a scoped lock
or a scoped try lock
to provide a non-recursive mutex
that supports test and return.
Objects of class try_mutex cannot be copied.
try_mutex::try_mutextry_mutex();
The constructor constructs a try_mutex in the unlocked state.
try_mutex::~try_mutex~try_mutex();
Precondition: the object must not be locked.
The destructor releases any resources used by the object.
timed_mutexclass timed_mutex
{
public:
timed_mutex();
~timed_mutex();
typedef SL0 scoped_lock;
typedef SL1 scoped_try_lock;
typedef SL2 scoped_timed_lock;
// exposition only
private:
// not implemented
timed_mutex(const timed_mutex&);
timed_mutex& operator= (const timed_mutex&);
};
The class describes an object that
can be used with a scoped lock,
a scoped try lock
or a scoped timed lock
to provide a non-recursive mutex
that supports test and return
and timeout.
Objects of class timed_mutex cannot be copied.
timed_mutex::timed_mutextimed_mutex();
The constructor constructs a timed_mutex in the unlocked state.
timed_mutex::~timed_mutex~timed_mutex();
Precondition: the object must not be locked.
The destructor releases any resources used by the object.
Every mutual exclusion class mtx defines a nested
type mtx::scoped_lock that can be used to create a
lock object for an object of the type mtx.
A lock object is an object whose constructor locks an associated mutex object and whose destructor unlocks the mutex object. Thus, proper unlocking is guaranteed in the presence of exceptions. Lock objects cannot be copied.
class mtx::scoped_lock
{
public:
typedef mtx mutex_type;
scoped_lock(mtx& m);
scoped_lock(mtx& m, bool lck);
~scoped_lock();
operator const void *() const;
bool locked() const;
void lock();
void unlock();
// exposition only
private:
mtx& mm;
bool is_locked;
// not implemented
scoped_lock::scoped_lock(const scoped_lock&);
scoped_lock& scoped_lock::operator= (const scoped_lock&);
};
scoped_lock::lockvoid lock();
The member function locks the stored mutual exclusion object mm
and sets the stored value is_locked to true.
scoped_lock::lockedbool locked() const;
The member function returns the stored value is_locked.
scoped_lock::mutex_typetypedef mtx mutex_type;
The nested type is a synonym for the containing type mtx.
scoped_lock::operator const void *operator const void *() const;
The member function returns 0 if the stored value is_locked is false,
otherwise a non-0 pointer value.
scoped_lock::scoped_lockscoped_lock(mtx& m); scoped_lock(mtx& m, bool lck);
The first constructor constructs a scoped_lock object with stored
value mm set to m and then calls lock.
The second constructor constructs a scoped_lock object with stored
value mm set to m. If lck is true
the constructor calls lock. Otherwise the
stored value is_locked is set to false.
scoped_lock::~scoped_lock~scoped_lock();
The destructor calls unlock if the stored value is_locked
is true. Otherwise the destructor does nothing.
scoped_lock::unlockvoid unlock();
The member function unlocks the stored mutual exclusion object mm
and sets the stored value is_locked to false.
Note that if mm is a recursive
mutex unlocking mm doesn't necessarily put mm into
the unlocked state.
A mutual exclusion class mtx that supports
test and return
defines a nested type mtx::scoped_try_lock
that can be used to create a
lock object for an object of the type mtx.
class mtx::scoped_try_lock
{
public:
typedef mtx mutex_type;
scoped_try_lock(mtx& m);
scoped_try_lock(mtx& m, bool lck);
~scoped_try_lock();
operator const void *() const;
bool locked() const;
void lock();
bool try_lock();
void unlock();
// exposition only
private:
mtx& mm;
bool is_locked;
// not implemented
scoped_try_lock::scoped_try_lock(const scoped_try_lock&);
scoped_try_lock& scoped_try_lock::operator= (const scoped_try_lock&);
};
scoped_try_lock::lockvoid lock();
The member function locks the stored mutual exclusion object mm
and sets the stored value is_locked to true.
scoped_try_lock::lockedbool locked() const;
The member function returns the stored value is_locked.
scoped_try_lock::mutex_typetypedef mtx mutex_type;
The nested type is a synonym for the containing type mtx.
scoped_try_lock::operator const void *operator const void *() const;
The member function returns 0 if the stored value is_locked is false,
otherwise a non-0 pointer value.
scoped_try_lock::scoped_try_lockscoped_try_lock(mtx& m); scoped_try_lock(mtx& m, bool lck);
The first constructor constructs a scoped_try_lock object with stored
value mm set to m, then calls try_lock.
The second constructor constructs a scoped_try_lock object with stored
value mm set to m. If lck is true
the constructor calls lock. Otherwise the
stored value is_locked is set to false.
scoped_try_lock::~scoped_try_lock~scoped_try_lock();
The destructor calls unlock if the stored value is_locked
is true. Otherwise the destructor does nothing.
scoped_try_lock::try_lockbool try_lock();
The member function attempts to lock the stored mutual exclusion object mm,
using its test and return mechanism,
sets the stored value is_locked to true if
the lock attempt was successful or false if it was not
successful, and returns the stored value is_locked.
scoped_try_lock::unlockvoid unlock();
The member function unlocks the stored mutual exclusion object mm
and sets the stored value is_locked to false. Note that if
mm is a recursive mutex unlocking
mm doesn't necessarily put mm into the unlocked state.
A mutual exclusion class mtx that supports
timeout
defines a nested type mtx::scoped_timed_lock
that can be used to create a
lock object for an object of the type mtx.
class mtx::scoped_timed_lock
{
public:
typedef mtx mutex_type;
scoped_timed_lock(mtx& m, const xtime& xt);
scoped_timed_lock(mtx& m, bool lck);
~scoped_timed_lock();
operator const void *() const;
bool locked() const;
void lock();
bool timed_lock(const xtime& xt);
void unlock();
// exposition only
private:
mtx& mm;
bool is_locked;
// not implemented
scoped_timed_lock::scoped_timed_lock(const scoped_timed_lock&);
scoped_timed_lock& scoped_timed_lock::operator= (const scoped_timed_lock&);
};
scoped_timed_lock::lockvoid lock();
The member function locks the stored mutual exclusion object mm
and sets the stored value is_locked to true.
scoped_timed_lock::lockedbool locked() const;
The member function returns the stored value is_locked.
scoped_timed_lock::mutex_typetypedef mtx mutex_type;
The nested type is a synonym for the containing type mtx.
scoped_timed_lock::operator const void *operator const void *() const;
The member function returns 0 if the stored value is_locked is false,
otherwise a non-0 pointer value.
scoped_timed_lock::scoped_timed_lockscoped_timed_lock(mtx& m, const xtime& xt); scoped_timed_lock(mtx& m, bool lck);
The first constructor constructs a scoped_timed_lock object with stored
value mm set to m, then calls timed_lock(xt).
The second constructor constructs a scoped_timed_lock object with stored
value mm set to m. If lck is true
the constructor calls lock. Otherwise the
stored value is_locked is set to false.
scoped_timed_lock::~scoped_timed_lock~scoped_timed_lock();
The destructor calls unlock if the stored value is_locked
is true. Otherwise the destructor does nothing.
scoped_timed_lock::timed_lockbool timed_lock(const xtime& xt);
The member function attempts to lock the stored mutual exclusion object mm,
using its timeout mechanism to avoid blocking beyond the time
specified by the xtime object xt,
sets the stored value is_locked to true if the lock
attempt was successful or false if it was not usccessful,
and returns the stored value is_locked.
scoped_timed_lock::unlockvoid unlock();
The member function unlocks the stored mutual exclusion object mm
and sets the stored value is_locked to false. Note that if
mm is a recursive mutex unlocking
mm doesn't necessarily put mm into the unlocked state.
See also the Table of Contents and the Index.
Copyright © 1992-2013 by Dinkumware, Ltd. Portions derived from work copyright © 2001 by William E. Kempf. All rights reserved.