2008-12-21 21:17:35 +02:00
|
|
|
#ifndef CTHREADHELPER_H
|
|
|
|
#define CTHREADHELPER_H
|
|
|
|
|
2008-08-06 16:18:28 +03:00
|
|
|
#include "global.h"
|
|
|
|
#include <boost/function.hpp>
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
typedef boost::function<void()> Task;
|
|
|
|
|
|
|
|
class CThreadHelper
|
|
|
|
{
|
|
|
|
boost::mutex rtinm;
|
|
|
|
int currentTask, amount, threads;
|
|
|
|
std::vector<Task> *tasks;
|
|
|
|
|
|
|
|
|
|
|
|
void processTasks();
|
|
|
|
public:
|
|
|
|
CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads);
|
|
|
|
void run();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T> inline void setData(T * data, boost::function<T()> func)
|
|
|
|
{
|
|
|
|
*data = func();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \
|
|
|
|
(boost::bind(&setData<TYPE>,&DESTINATION,FUNCTION_TO_GET))
|
|
|
|
#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \
|
|
|
|
(GET_DATA \
|
|
|
|
(SDL_Surface*,SUR_DESTINATION,\
|
|
|
|
boost::function<SDL_Surface*()>(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true))))
|
|
|
|
#define GET_DEF(DESTINATION, DEF_NAME) \
|
|
|
|
(GET_DATA \
|
|
|
|
(CDefHandler*,DESTINATION,\
|
|
|
|
boost::function<CDefHandler*()>(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL))))
|
|
|
|
#define GET_DEF_ESS(DESTINATION, DEF_NAME) \
|
|
|
|
(GET_DATA \
|
|
|
|
(CDefEssential*,DESTINATION,\
|
2008-12-18 10:21:24 +02:00
|
|
|
boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL))))
|
2008-12-21 21:17:35 +02:00
|
|
|
#endif //CTHREADHELPER_H
|