2009-04-16 14:14:13 +03:00
|
|
|
#ifndef __CONDSH_H__
|
|
|
|
#define __CONDSH_H__
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CondSh.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T> struct CondSh
|
|
|
|
{
|
|
|
|
T data;
|
|
|
|
boost::condition_variable cond;
|
|
|
|
boost::mutex mx;
|
|
|
|
CondSh(){};
|
|
|
|
CondSh(T t){data = t;};
|
|
|
|
void set(T t){mx.lock();data=t;mx.unlock();}; //set data
|
|
|
|
void setn(T t){mx.lock();data=t;mx.unlock();cond.notify_all();}; //set data and notify
|
|
|
|
T get(){boost::unique_lock<boost::mutex> lock(mx); return data;};
|
|
|
|
};
|
|
|
|
#endif // __CONDSH_H__
|