Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * thread_list.h - Thread list 00004 * 00005 * Created: Tue Oct 31 18:04:31 2006 00006 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __CORE_THREADING_THREAD_LIST_H_ 00025 #define __CORE_THREADING_THREAD_LIST_H_ 00026 00027 #include <core/exception.h> 00028 #include <core/threading/thread.h> 00029 #include <core/threading/thread_initializer.h> 00030 #include <core/threading/thread_finalizer.h> 00031 #include <core/utils/lock_list.h> 00032 00033 #include <utility> 00034 #include <string> 00035 00036 namespace fawkes { 00037 00038 00039 class ThreadList; 00040 class Mutex; 00041 class Barrier; 00042 class InterruptibleBarrier; 00043 00044 class ThreadListSealedException : public Exception 00045 { 00046 public: 00047 ThreadListSealedException(const char *operation); 00048 }; 00049 00050 class ThreadListNotSealedException : public Exception 00051 { 00052 public: 00053 ThreadListNotSealedException(const char *format, ...); 00054 }; 00055 00056 00057 class ThreadList : private LockList<Thread *> 00058 { 00059 public: 00060 ThreadList(const char *tlname = ""); 00061 ThreadList(bool maintain_barrier, const char *tlname = ""); 00062 ThreadList(const ThreadList &tl); 00063 ~ThreadList(); 00064 00065 const char * name(); 00066 void set_name(const char *format, ...); 00067 00068 void seal(); 00069 bool sealed(); 00070 00071 void init(ThreadInitializer *initializer, ThreadFinalizer *finalizer); 00072 bool prepare_finalize(ThreadFinalizer *finalizer); 00073 void finalize(ThreadFinalizer *finalizer); 00074 void cancel_finalize(); 00075 void set_prepfin_hold(bool hold); 00076 00077 void wakeup(); 00078 void wakeup(Barrier *barrier); 00079 void wakeup_unlocked(); 00080 void wakeup_unlocked(Barrier *barrier); 00081 void wakeup_and_wait(unsigned int timeout_sec = 0, 00082 unsigned int timeout_nanosec = 0); 00083 void start(); 00084 void stop(); 00085 void cancel(); 00086 void join(); 00087 00088 void try_recover(std::list<std::string> &recovered_threads); 00089 void set_maintain_barrier(bool maintain_barrier); 00090 00091 void force_stop(ThreadFinalizer *finalizer); 00092 00093 void push_front(Thread *thread); 00094 void push_front_locked(Thread *thread); 00095 void push_back(Thread *thread); 00096 void push_back_locked(Thread *thread); 00097 void clear(); 00098 void pop_back(); 00099 void pop_front(); 00100 ThreadList::iterator erase(iterator pos); 00101 00102 void remove(Thread *thread); 00103 void remove_locked(Thread *thread); 00104 00105 using LockList<Thread *>::begin; 00106 using LockList<Thread *>::end; 00107 using LockList<Thread *>::iterator; 00108 using LockList<Thread *>::lock; 00109 using LockList<Thread *>::try_lock; 00110 using LockList<Thread *>::unlock; 00111 using LockList<Thread *>::size; 00112 using LockList<Thread *>::empty; 00113 using LockList<Thread *>::front; 00114 using LockList<Thread *>::back; 00115 00116 ThreadList & operator= (const ThreadList & tl); 00117 00118 00119 private: 00120 void notify_of_failed_init(); 00121 void update_barrier(); 00122 00123 private: 00124 char *__name; 00125 bool __sealed; 00126 Mutex *__finalize_mutex; 00127 InterruptibleBarrier *__wnw_barrier; 00128 00129 std::list<std::pair<InterruptibleBarrier *, ThreadList> > __wnw_bad_barriers; 00130 std::list<std::pair<InterruptibleBarrier *, ThreadList> >::iterator __wnw_bbit; 00131 }; 00132 00133 00134 } // end namespace fawkes 00135 00136 #endif