Ceylan::System::Synchronized< X > Class Template Reference

Template defining generically objects (notably numerical datatypes) protected by a mutex. More...

#include <CeylanSynchronized.h>

Inheritance diagram for Ceylan::System::Synchronized< X >:
Inheritance graph
[legend]
Collaboration diagram for Ceylan::System::Synchronized< X >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Synchronized (X value)
 Value assigned constructor.
SynchronizedsetValue (const volatile X &value)
 Sets value.
const volatile X & getValue () const volatile
 Returns the current value.
Synchronizedoperator= (const X &value)
 Assignment operator.
 operator X () const volatile
 Conversion operator.
operator++ ()
 Prefixed increment operator (ex: ++x).
operator++ (int)
 Postfixed increment operator (ex: x++).
operator-- ()
 Prefixed decrement operator (ex: --x).
operator-- (int)
 Postfixed decrement operator (ex: x--).

Private Member Functions

 Synchronized ()
 Default constructor made private to ensure that it will be never called.
 Synchronized (const Synchronized &source)
 Copy constructor made private to ensure that it will be never called.
Synchronizedoperator= (const Synchronized &source)
 Assignment operator made private to ensure that it will be never called.

Private Attributes

volatile X _value
 The synchronized resource.
Mutex _mutex
 The protecting mutex.

Detailed Description

template<typename X>
class Ceylan::System::Synchronized< X >

Template defining generically objects (notably numerical datatypes) protected by a mutex.

Any write operation first obtains a lock, then modifies the value, and unlocks the mutex, thus synchronizing the access to the value.

Note:
This template still ought to be thoroughfully tested.
See also:
Mutex, POSIX threads

Definition at line 60 of file CeylanSynchronized.h.


Constructor & Destructor Documentation

template<typename X>
Ceylan::System::Synchronized< X >::Synchronized ( value  )  [inline]

Value assigned constructor.

Note:
This constructor would not be convenient if it used the 'explicit' keyword.

Definition at line 74 of file CeylanSynchronized.h.

template<typename X>
Ceylan::System::Synchronized< X >::Synchronized (  )  [private]

Default constructor made private to ensure that it will be never called.

template<typename X>
Ceylan::System::Synchronized< X >::Synchronized ( const Synchronized< X > &  source  )  [private]

Copy constructor made private to ensure that it will be never called.

Calls such as: Synchronized<int> number = 0 ; should be rewritten in: Synchronized<int> number( 0 ) ; otherwise a copy constructor would be needed.


Member Function Documentation

template<typename X>
const volatile X& Ceylan::System::Synchronized< X >::getValue (  )  const volatile [inline]

Returns the current value.

Definition at line 106 of file CeylanSynchronized.h.

template<typename X>
Ceylan::System::Synchronized< X >::operator X (  )  const volatile [inline]

Conversion operator.

Definition at line 131 of file CeylanSynchronized.h.

References Ceylan::System::Synchronized< X >::_value.

template<typename X>
X Ceylan::System::Synchronized< X >::operator++ ( int   )  [inline]

Postfixed increment operator (ex: x++).

Definition at line 155 of file CeylanSynchronized.h.

template<typename X>
X Ceylan::System::Synchronized< X >::operator++ (  )  [inline]

Prefixed increment operator (ex: ++x).

Definition at line 141 of file CeylanSynchronized.h.

Referenced by Ceylan::System::Synchronized< bool >::operator++(), and Ceylan::System::Synchronized< ThreadCount >::operator++().

template<typename X>
X Ceylan::System::Synchronized< X >::operator-- ( int   )  [inline]

Postfixed decrement operator (ex: x--).

Definition at line 178 of file CeylanSynchronized.h.

template<typename X>
X Ceylan::System::Synchronized< X >::operator-- (  )  [inline]

Prefixed decrement operator (ex: --x).

Definition at line 165 of file CeylanSynchronized.h.

Referenced by Ceylan::System::Synchronized< bool >::operator--(), and Ceylan::System::Synchronized< ThreadCount >::operator--().

template<typename X>
Synchronized& Ceylan::System::Synchronized< X >::operator= ( const Synchronized< X > &  source  )  [private]

Assignment operator made private to ensure that it will be never called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

template<typename X>
Synchronized& Ceylan::System::Synchronized< X >::operator= ( const X &  value  )  [inline]

Assignment operator.

Definition at line 121 of file CeylanSynchronized.h.

template<typename X>
Synchronized& Ceylan::System::Synchronized< X >::setValue ( const volatile X &  value  )  [inline]

Member Data Documentation

template<typename X>
Mutex Ceylan::System::Synchronized< X >::_mutex [private]
template<typename X>
volatile X Ceylan::System::Synchronized< X >::_value [private]

The documentation for this class was generated from the following file:
Generated on Mon Nov 29 13:43:13 2010 for Ceylan by  doxygen 1.6.3