CThreadHelper.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef __CTHREADHELPER_H__
  2. #define __CTHREADHELPER_H__
  3. #include "global.h"
  4. #include <boost/function.hpp>
  5. #include <boost/thread.hpp>
  6. typedef boost::function<void()> Task;
  7. class CThreadHelper
  8. {
  9. boost::mutex rtinm;
  10. int currentTask, amount, threads;
  11. std::vector<Task> *tasks;
  12. void processTasks();
  13. public:
  14. CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads);
  15. void run();
  16. };
  17. template <typename T> inline void setData(T * data, boost::function<T()> func)
  18. {
  19. *data = func();
  20. }
  21. #define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \
  22. (boost::bind(&setData<TYPE>,&DESTINATION,FUNCTION_TO_GET))
  23. #define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \
  24. (GET_DATA \
  25. (SDL_Surface*,SUR_DESTINATION,\
  26. boost::function<SDL_Surface*()>(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true))))
  27. #define GET_DEF(DESTINATION, DEF_NAME) \
  28. (GET_DATA \
  29. (CDefHandler*,DESTINATION,\
  30. boost::function<CDefHandler*()>(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL))))
  31. #define GET_DEF_ESS(DESTINATION, DEF_NAME) \
  32. (GET_DATA \
  33. (CDefEssential*,DESTINATION,\
  34. boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL))))
  35. #endif // __CTHREADHELPER_H__