G
Gernot Frisch
Hi,
is it possible (win32, *nix, only) to create a template class that
locks/unlocks a mutex every time the value of an object is used?
Like:
template <typename T> class wrapper
{
public:
wrapper() :m_t() {}
wrapper(const T& t) :m_t(t) {}
operator T() const
{
T t;
lock();
t=m_t;
unlock();
return t;
}
T operator = (const T& t)
{
lock();
m_t = t;
unlock();
return t;
}
private:
T m_t;
void lock()const {/*EnterCricitcalSection...whatever*/}
void unlock()const{/*LeaveCriticalSection...*/}
};
int main()
{
wrapper<int> i = 13;
return i;
}
is it possible (win32, *nix, only) to create a template class that
locks/unlocks a mutex every time the value of an object is used?
Like:
template <typename T> class wrapper
{
public:
wrapper() :m_t() {}
wrapper(const T& t) :m_t(t) {}
operator T() const
{
T t;
lock();
t=m_t;
unlock();
return t;
}
T operator = (const T& t)
{
lock();
m_t = t;
unlock();
return t;
}
private:
T m_t;
void lock()const {/*EnterCricitcalSection...whatever*/}
void unlock()const{/*LeaveCriticalSection...*/}
};
int main()
{
wrapper<int> i = 13;
return i;
}