71 lines
913 B
C++
71 lines
913 B
C++
#ifndef _THREAD_MONITOR_HPP_
|
|
#define _THREAD_MONITOR_HPP_
|
|
#ifndef _THREAD_MUTEX_HPP_
|
|
#include <thread/mutex.hpp>
|
|
#endif
|
|
|
|
template <class T>
|
|
class Monitor
|
|
{
|
|
public:
|
|
Monitor(void);
|
|
virtual ~Monitor();
|
|
void enter(void);
|
|
void leave(void);
|
|
T *operator->(void);
|
|
operator T*(void);
|
|
Monitor &operator=(T *pObj);
|
|
private:
|
|
T *mlpObj;
|
|
Mutex mMutex;
|
|
};
|
|
|
|
template <class T>
|
|
inline
|
|
Monitor<T>::Monitor(void)
|
|
: mlpObj(0)
|
|
{
|
|
}
|
|
|
|
template <class T>
|
|
inline
|
|
Monitor<T>::~Monitor()
|
|
{
|
|
}
|
|
|
|
template <class T>
|
|
inline
|
|
T *Monitor<T>::operator->(void)
|
|
{
|
|
return mlpObj;
|
|
}
|
|
|
|
template <class T>
|
|
inline
|
|
Monitor<T>::operator T*(void)
|
|
{
|
|
return mlpObj;
|
|
}
|
|
|
|
template <class T>
|
|
inline
|
|
Monitor<T> &Monitor<T>::operator=(T *pObj)
|
|
{
|
|
mlpObj=pObj;
|
|
return *this;
|
|
}
|
|
|
|
template <class T>
|
|
inline
|
|
void Monitor<T>::enter(void)
|
|
{
|
|
mMutex.requestMutex();
|
|
}
|
|
|
|
template <class T>
|
|
inline
|
|
void Monitor<T>::leave(void)
|
|
{
|
|
mMutex.releaseMutex();
|
|
}
|
|
#endif |