CThreadHelper.h 1.1 KB

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