CondSh.h 695 B

1234567891011121314151617181920212223242526
  1. #ifndef __CONDSH_H__
  2. #define __CONDSH_H__
  3. #include <boost/thread.hpp>
  4. /*
  5. * CondSh.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. template <typename T> struct CondSh
  14. {
  15. T data;
  16. boost::condition_variable cond;
  17. boost::mutex mx;
  18. CondSh(){};
  19. CondSh(T t){data = t;};
  20. void set(T t){mx.lock();data=t;mx.unlock();}; //set data
  21. void setn(T t){mx.lock();data=t;mx.unlock();cond.notify_all();}; //set data and notify
  22. T get(){boost::unique_lock<boost::mutex> lock(mx); return data;};
  23. };
  24. #endif // __CONDSH_H__