00001 /****************************************************************************** 00002 * __ _ _ _ _ _ _____ * 00003 * | \ / | | | | | | | | | | ___| * 00004 * | \/ | | | | | | | | | | |_ * 00005 * | | | | | | | | | | | _| * 00006 * | |\/| | | | | |__ | |__ | | | |__ * 00007 * |_| |_| |_| |____| |____| |_| |____| * 00008 * __________________________________________________________________________ * 00009 * Multifunctional Library For Image Processing * 00010 * * 00011 * * 00012 * * 00013 * (c) Copyright 2007 by Humbert Florent * 00014 * * 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU General Public License as published by * 00017 * the Free Software Foundation; only version 2 of the License. * 00018 * * 00019 * This program is distributed in the hope that it will be useful, * 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00022 * GNU General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU General Public License * 00025 * along with this program; if not, write to the Free Software * 00026 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 00027 * 02111-1307, USA. * 00028 ******************************************************************************/ 00029 00032 #ifndef _MILLIETHREADGROUP_HPP_ 00033 #define _MILLIETHREADGROUP_HPP_ 00034 00035 #include <vector> 00036 #include <iostream> 00037 00038 #include "GThread.hpp" 00039 #include "Mutex.hpp" 00040 00041 00042 namespace Millie 00043 { 00081 class ThreadGroup 00082 { 00083 private: 00084 void init(); 00085 bool _isRunning; 00086 bool _isStarted; 00087 00088 std::string _name; 00089 std::vector<GThread*> _vectThread; 00090 std::vector<bool> _vectWaiting; 00091 00092 pthread_mutex_t _mutexWaitAll; 00093 pthread_cond_t _waitSynchro; 00094 00095 unsigned int _nbwaitingthread; 00096 00097 Mutex _synchronizedWaitingThread; 00098 Mutex _synchronizedIsRunning; 00099 Mutex _synchronizedRun; 00100 Mutex _synchronizedIsStarted; 00101 Mutex _synchronizedNbThread; 00102 Mutex _synchronizedWaitAllNotify; 00103 00104 int getNbWaitingThread(); 00105 00106 00107 protected: 00108 00109 bool threadWaitAll(GThread * t, pthread_mutex_t ** mutex, pthread_cond_t ** wait); 00110 00111 public: 00112 00116 ThreadGroup(); 00117 00121 ThreadGroup(const std::string & name); 00122 00129 bool isRunning(); 00130 00139 bool isStarted(); 00140 00144 const std::string & getName() const; 00145 00149 void setName(const std::string & name); 00150 00157 void joinAll(); 00158 00164 unsigned int getNbGThread(); 00165 00173 GThread & operator[](unsigned int pos); 00174 00175 int getNbWaitingGThread(); 00176 00182 void notifyAll(); 00183 00189 void startAll(); 00190 00202 void add(GThread * thread) 00203 ; 00204 00210 virtual ~ThreadGroup(); 00211 00212 friend class GThread; 00213 }; 00214 00215 } 00216 00217 #endif