MAK Data Logger API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
MAKLogger::DtThreadSafe< T > Class Template Reference

a thread safe interface to a value. More...

+ Inheritance diagram for MAKLogger::DtThreadSafe< T >:
+ Collaboration diagram for MAKLogger::DtThreadSafe< T >:

Classes

class  ConstLockedProxy
 Private class that provides a locked call to the const object. More...
 
class  LockedProxy
 Private class that provides a locked call to the object. More...
 
class  SequenceLockImpl
 Private class which implements the Sequence lock. More...
 

Public Member Functions

 DtThreadSafe (const T &value)
 ! DtThreadSafe Implementation More...
 
 operator T () const
 Proxy type copy operator. More...
 
LockedProxy operator-> ()
 Proxy pointer access operator. More...
 
ConstLockedProxy operator-> () const
 Proxy pointer access operator. More...
 
DtThreadSafe< T > & operator= (const DtThreadSafe< T > &orig)
 Locked Copy operator,. More...
 
DtThreadSafe< T > & operator= (const T &orig)
 Locked Copy operator, from safe value. More...
 
DtScopedSequenceLock sequenceLock ()
 Request a sequence lock, this object will maintain a lock on the object during it's life-time. More...
 

Protected Member Functions

void lockObject ()
 Lock the external object. More...
 
void unlockObject ()
 Unlock the external object. More...
 

Protected Attributes

myValue
 Value which is to be thread safe. More...
 
DtScopedLock * myExternalLock
 The external lock which allows the sequence lock. More...
 
DtMutex myLockMutex
 The mutex which is used to lock when created the external lock. More...
 
DtMutex myMutex
 The mutex which is used to make the object threadsafe. More...
 

Friends

class SequenceLockImpl
 

Detailed Description

template<typename T>
class MAKLogger::DtThreadSafe< T >

a thread safe interface to a value.

Which can be shared between threads. DtThreadSafe provides a safe access to T value. T is assumed to have value semantics and is copyable. DtThreadSafe provides a locked pointer to the underlying value interface.

Warning
Thread safety is only assumed for the duration a single call. Any references, pointers or proxy objects returns (for example iterators) are not thread safe.

Example: Thread safe iteration.

* DtThreadSafe<std::vector<int> > aVector;
* ...
* {
* DtScopedSequenceLock lock = aVector.sequenceLock();
* std::vector<int>::iterator start = aVector->begin();
* std::vector<int>::iterator end = aVector->end();
* for(;start != end;++start)
* {
*
*
* *start = 0;
* }
* }
*

Constructor & Destructor Documentation

template<typename T>
MAKLogger::DtThreadSafe< T >::DtThreadSafe ( const T &  value)

! DtThreadSafe Implementation

Member Function Documentation

template<typename T >
void MAKLogger::DtThreadSafe< T >::lockObject ( )
protected

Lock the external object.

template<typename T >
MAKLogger::DtThreadSafe< T >::operator T ( ) const

Proxy type copy operator.

template<typename T >
DtThreadSafe< T >::LockedProxy MAKLogger::DtThreadSafe< T >::operator-> ( )

Proxy pointer access operator.

The locked proxy will maintain a lock for the call (typically and the line).

template<typename T >
DtThreadSafe< T >::ConstLockedProxy MAKLogger::DtThreadSafe< T >::operator-> ( ) const

Proxy pointer access operator.

The locked proxy will maintain a lock for the call (typically and the line).

template<typename T>
DtThreadSafe< T > & MAKLogger::DtThreadSafe< T >::operator= ( const DtThreadSafe< T > &  orig)

Locked Copy operator,.

template<typename T>
DtThreadSafe< T > & MAKLogger::DtThreadSafe< T >::operator= ( const T &  orig)

Locked Copy operator, from safe value.

template<typename T >
DtScopedSequenceLock MAKLogger::DtThreadSafe< T >::sequenceLock ( )

Request a sequence lock, this object will maintain a lock on the object during it's life-time.

Note: this is fairly expensive and should be called sparingly.

Referenced by MAKLogger::DtSharedQueue< T >::move(), and MAKLogger::DtSharedQueue< T >::pop().

template<typename T >
void MAKLogger::DtThreadSafe< T >::unlockObject ( )
protected

Unlock the external object.

Friends And Related Function Documentation

template<typename T>
friend class SequenceLockImpl
friend

Member Data Documentation

template<typename T>
DtScopedLock* MAKLogger::DtThreadSafe< T >::myExternalLock
protected

The external lock which allows the sequence lock.

This lock is not used unless a sequence is requested.

template<typename T>
DtMutex MAKLogger::DtThreadSafe< T >::myLockMutex
protected

The mutex which is used to lock when created the external lock.

template<typename T>
DtMutex MAKLogger::DtThreadSafe< T >::myMutex
mutableprotected

The mutex which is used to make the object threadsafe.

template<typename T>
T MAKLogger::DtThreadSafe< T >::myValue
protected

Value which is to be thread safe.


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

Document ID: Generated on Thu Dec 18 15:35:09 EST 2025 from SVN revision 282494
Copyright © 2024 MAK Technologies. All Rights Reserved (www.mak.com)