MRXT: The Multi-Robot eXploration Tool
Multi-Robot autonomous exploration and mapping simulator.
|
00001 #pragma once 00002 #ifndef __STEP_EVENT__ 00003 #define __STEP_EVENT__ 00004 00005 #include "ClMutex.h" 00006 #include <vector> 00007 #ifndef WIN32 00008 //#include <semaphore.h> 00009 #endif 00010 00011 /** 00012 * @brief Thread synchronization auxiliary class for waiting thread queues 00013 * 00014 */ 00015 class waitingThread{ 00016 private: 00017 #ifdef WIN32 00018 HANDLE sem; 00019 #else 00020 pthread_cond_t cond; 00021 #endif 00022 int stepToUnclock; 00023 bool posted; 00024 public: 00025 waitingThread(); 00026 virtual ~waitingThread(); 00027 void wait(); 00028 void post(); 00029 void setStep(int step); 00030 int getStep(); 00031 bool isPosted(); 00032 }; 00033 00034 /** 00035 * @brief Thread synchronization using a waif for step model 00036 * 00037 */ 00038 class stepEventManager 00039 { 00040 private: 00041 00042 00043 ClMutex mut; 00044 int currentStep; 00045 std::vector<waitingThread*> waitingList; 00046 public: 00047 stepEventManager(); 00048 void waitForStep(int step); 00049 void step(); 00050 int getStep(){return currentStep;}; 00051 void resetCounter(){currentStep=0;}; 00052 }; 00053 00054 00055 /** 00056 * @brief Thread synchronization with a producer/consumer model 00057 * 00058 */ 00059 class production{ 00060 private: 00061 int itemProd; 00062 int totalSize; 00063 int prodWaiting; 00064 int consWaiting; 00065 00066 #ifndef WIN32 00067 pthread_mutex_t mutex; 00068 pthread_cond_t producerWaiting; 00069 pthread_cond_t consumerWaiting; 00070 #else 00071 HANDLE mutex; 00072 HANDLE producerWaiting; 00073 HANDLE consumerWaiting; 00074 #endif 00075 00076 public: 00077 production(int size=1); 00078 virtual ~production(); 00079 00080 void beginProduction(); 00081 void endProduction(); 00082 00083 void beginConsumition(); 00084 void endConsumition(); 00085 00086 }; 00087 00088 00089 #endif 00090