Hydra 0.20
hydra.src/hydra/ThreadData.h
00001 
00002 /*
00003  * Copyright (c) 2009 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_HYDRA_THREADAREA_H__
00009 #define __INCLUDED_HYDRA_THREADAREA_H__
00010 
00011 #include <QMutex>
00012 
00013 namespace hydra
00014 {
00015   template <class T> class MutexData;
00016 
00017   template <class T> class MutexPtr;
00018 }
00019 
00020 template <class T> class hydra::MutexData
00021 {
00022   public:
00023     typedef T DataType;
00024   public:
00025     volatile T data;
00026     QMutex mutex;
00027 };
00028 
00029 template <class T> class hydra::MutexPtr
00030 {
00031   public:
00032     typedef T DataType;
00033   public:
00034     MutexPtr(MutexData<T> &sa)
00035       : dm_ptr(const_cast<T*>(&sa.data)), dm_data(sa)
00036       { dm_data.mutex.lock(); }
00037     ~MutexPtr() { dm_data.mutex.unlock(); }
00038 
00039     T& operator*(void) { return *dm_ptr; }
00040     T* operator->(void) { return dm_ptr; }
00041   private:
00042     T * dm_ptr;
00043     MutexData<T> &dm_data;
00044 };
00045 
00046 #endif
00047 
 All Classes Namespaces Functions Variables