IBR-DTNSuite  0.8
ibrcommon/ibrcommon/thread/ThreadsafeReference.h
Go to the documentation of this file.
00001 #ifndef THREADSAFEREFERENCE_H_
00002 #define THREADSAFEREFERENCE_H_
00003 
00004 #include "MutexLock.h"
00005 
00006 namespace ibrcommon {
00007 
00008         template <class T>
00009         class ThreadsafeReference
00010         {
00011         public:
00012                 ThreadsafeReference(T& ref, MutexInterface& mutex)
00013                         : _item(ref), _l(mutex)
00014                 {}
00015                 T& operator*() const
00016                 {
00017                         return _item;
00018                 }
00019         private:
00020                 T& _item;
00021                 MutexLock _l;
00022         };
00023 
00024 } // namespace ibrcommon
00025 
00026 #endif // THREADSAFEREFERENCE_H_