diff --git a/CThreadHelper.cpp b/CThreadHelper.cpp new file mode 100644 index 000000000..448f99c37 --- /dev/null +++ b/CThreadHelper.cpp @@ -0,0 +1,35 @@ +#include "CThreadHelper.h" +#include +#include +CThreadHelper::CThreadHelper(std::vector > *Tasks, int Threads) +{ + currentTask = 0; amount = Tasks->size(); + tasks = Tasks; + threads = Threads; +} +void CThreadHelper::run() +{ + boost::thread_group grupa; + for(int i=0;i= amount) + { + rtinm.unlock(); + break; + } + else + { + ++currentTask; + rtinm.unlock(); + (*tasks)[pom](); + } + } +} \ No newline at end of file diff --git a/CThreadHelper.h b/CThreadHelper.h new file mode 100644 index 000000000..61cd9e462 --- /dev/null +++ b/CThreadHelper.h @@ -0,0 +1,38 @@ +#include "global.h" +#include +#include +typedef boost::function Task; + +class CThreadHelper +{ + boost::mutex rtinm; + int currentTask, amount, threads; + std::vector *tasks; + + + void processTasks(); +public: + CThreadHelper(std::vector > *Tasks, int Threads); + void run(); +}; + +template inline void setData(T * data, boost::function func) +{ + *data = func(); +} + + +#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \ + (boost::bind(&setData,&DESTINATION,FUNCTION_TO_GET)) +#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \ + (GET_DATA \ + (SDL_Surface*,SUR_DESTINATION,\ + boost::function(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true)))) +#define GET_DEF(DESTINATION, DEF_NAME) \ + (GET_DATA \ + (CDefHandler*,DESTINATION,\ + boost::function(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL)))) +#define GET_DEF_ESS(DESTINATION, DEF_NAME) \ + (GET_DATA \ + (CDefEssential*,DESTINATION,\ + boost::function(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL)))) \ No newline at end of file