mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Missing files
This commit is contained in:
		
							
								
								
									
										35
									
								
								CThreadHelper.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								CThreadHelper.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| #include "CThreadHelper.h" | ||||
| #include <boost/thread.hpp> | ||||
| #include <boost/bind.hpp> | ||||
| CThreadHelper::CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads) | ||||
| { | ||||
| 	currentTask = 0; amount = Tasks->size(); | ||||
| 	tasks = Tasks; | ||||
| 	threads = Threads; | ||||
| } | ||||
| void CThreadHelper::run() | ||||
| { | ||||
| 	boost::thread_group grupa; | ||||
| 	for(int i=0;i<threads;i++) | ||||
| 		grupa.create_thread(boost::bind(&CThreadHelper::processTasks,this)); | ||||
| 	grupa.join_all(); | ||||
| } | ||||
| void CThreadHelper::processTasks() | ||||
| { | ||||
| 	int pom; | ||||
| 	while(true) | ||||
| 	{ | ||||
| 		rtinm.lock(); | ||||
| 		if((pom=currentTask) >= amount) | ||||
| 		{ | ||||
| 			rtinm.unlock(); | ||||
| 			break; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			++currentTask; | ||||
| 			rtinm.unlock(); | ||||
| 			(*tasks)[pom](); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										38
									
								
								CThreadHelper.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								CThreadHelper.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| #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,\ | ||||
| 		boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL)))) | ||||
		Reference in New Issue
	
	Block a user