Initial
This commit is contained in:
71
thread/MONITOR.HPP
Normal file
71
thread/MONITOR.HPP
Normal file
@@ -0,0 +1,71 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user