CThreadHelper.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef __CTHREADHELPER_H__
  2. #define __CTHREADHELPER_H__
  3. #include "global.h"
  4. #include <boost/function.hpp>
  5. #include <boost/thread.hpp>
  6. /*
  7. * CThreadHelper.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. typedef boost::function<void()> Task;
  16. class CThreadHelper
  17. {
  18. boost::mutex rtinm;
  19. int currentTask, amount, threads;
  20. std::vector<Task> *tasks;
  21. void processTasks();
  22. public:
  23. CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads);
  24. void run();
  25. };
  26. template <typename T> inline void setData(T * data, boost::function<T()> func)
  27. {
  28. *data = func();
  29. }
  30. #define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \
  31. (boost::bind(&setData<TYPE>,&DESTINATION,FUNCTION_TO_GET))
  32. #define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \
  33. (GET_DATA \
  34. (SDL_Surface*,SUR_DESTINATION,\
  35. boost::function<SDL_Surface*()>(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true))))
  36. #define GET_DEF(DESTINATION, DEF_NAME) \
  37. (GET_DATA \
  38. (CDefHandler*,DESTINATION,\
  39. boost::function<CDefHandler*()>(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL))))
  40. #define GET_DEF_ESS(DESTINATION, DEF_NAME) \
  41. (GET_DATA \
  42. (CDefEssential*,DESTINATION,\
  43. boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL))))
  44. #endif // __CTHREADHELPER_H__