Fawkes API
Fawkes Development Version
|
List of threads. More...
#include <>>
Public Member Functions | |
ThreadList (const char *tlname="") | |
Constructor. | |
ThreadList (bool maintain_barrier, const char *tlname="") | |
Constructor. | |
ThreadList (const ThreadList &tl) | |
Copy constructor. | |
~ThreadList () | |
Destructor. | |
const char * | name () |
Name of the thread list. | |
void | set_name (const char *format,...) |
Set name of thread. | |
void | seal () |
Seal the list. | |
bool | sealed () |
Check if list is sealed. | |
void | init (ThreadInitializer *initializer, ThreadFinalizer *finalizer) |
Initialize threads. | |
bool | prepare_finalize (ThreadFinalizer *finalizer) |
Prepare finalize. | |
void | finalize (ThreadFinalizer *finalizer) |
Finalize Threads. | |
void | cancel_finalize () |
Cancel finalization on all threads. | |
void | set_prepfin_hold (bool hold) |
Set prepfin hold on all threads. | |
void | wakeup () |
Wakeup all threads in list. | |
void | wakeup (Barrier *barrier) |
Wakeup all threads in list and have them wait for the barrier. | |
void | wakeup_unlocked () |
Wakeup all threads in list. | |
void | wakeup_unlocked (Barrier *barrier) |
Wakeup all threads in list and have them wait for the barrier. | |
void | wakeup_and_wait (unsigned int timeout_sec=0, unsigned int timeout_nanosec=0) |
Wakeup threads and wait for them to finish. | |
void | start () |
Start threads. | |
void | stop () |
Stop threads. | |
void | cancel () |
Cancel threads. | |
void | join () |
Join threads. | |
void | try_recover (std::list< std::string > &recovered_threads) |
Check if any of the bad barriers recovered. | |
void | set_maintain_barrier (bool maintain_barrier) |
Set if this thread list should maintain a barrier. | |
void | force_stop (ThreadFinalizer *finalizer) |
Force stop of all threads. | |
void | push_front (Thread *thread) |
Add thread to the front. | |
void | push_front_locked (Thread *thread) |
Add thread to the front with lock protection. | |
void | push_back (Thread *thread) |
Add thread to the end. | |
void | push_back_locked (Thread *thread) |
Add thread to the end with lock protection. | |
void | clear () |
Clear the list. | |
void | pop_back () |
Remove last element. | |
void | pop_front () |
Remove first element. | |
ThreadList::iterator | erase (iterator pos) |
Erase element at given position. | |
void | remove (Thread *thread) |
Remove with lock protection. | |
void | remove_locked (Thread *thread) |
Remove with lock protection. | |
ThreadList & | operator= (const ThreadList &tl) |
Assignment operator. |
Additional Inherited Members | |
![]() | |
LockList () | |
Constructor. | |
LockList (const LockList< Thread * > &ll) | |
Copy constructor. | |
virtual | ~LockList () |
Destructor. | |
virtual void | lock () const |
Lock list. | |
virtual bool | try_lock () const |
Try to lock list. | |
virtual void | unlock () const |
Unlock list. | |
RefPtr< Mutex > | mutex () const |
Get access to the internal mutex. | |
void | push_back_locked (const Thread *&x) |
Push element to list at back with lock protection. | |
void | push_front_locked (const Thread *&x) |
Push element to list at front with lock protection. | |
void | remove_locked (const Thread *&x) |
Remove element from list with lock protection. | |
LockList< Thread * > & | operator= (const LockList< Thread * > &ll) |
Copy values from another LockList. | |
LockList< Thread * > & | operator= (const std::list< Thread * > &l) |
Copy values from a standard list. | |
![]() | |
T | elements |
STL member. |
List of threads.
This is a list of threads derived from stl::list. It features special wakeup methods that will wakeup all threads in the list. The list can and must be locked in iterator operations and when adding or deleting elements from the list.
Definition at line 57 of file thread_list.h.
fawkes::ThreadList::ThreadList | ( | const char * | tlname = "" | ) |
Constructor.
tlname | optional name which is used for better readable error messages. |
Definition at line 94 of file thread_list.cpp.
References clear().
fawkes::ThreadList::ThreadList | ( | bool | maintain_barrier, |
const char * | tlname = "" |
||
) |
Constructor.
maintain_barrier | if true, an internal barrier is maintained during add and remove operations such that wakeup_and_wait() can be used. |
tlname | optional name which is used for better readable error messages. |
Definition at line 110 of file thread_list.cpp.
References clear().
fawkes::ThreadList::ThreadList | ( | const ThreadList & | tl | ) |
fawkes::ThreadList::~ThreadList | ( | ) |
Destructor.
Definition at line 136 of file thread_list.cpp.
void fawkes::ThreadList::cancel | ( | ) |
Cancel threads.
The threads are canceled. This operation is carried out unlocked. Lock it from the outside if needed. This is done because it is likely that this will be chained with other actions that require locking, thus you can lock the whole operation.
This is especially handy for detached threads. Since errorneous behavior has been seen when run inside gdb something like
shout be avoided. Instead use
Definition at line 461 of file thread_list.cpp.
void fawkes::ThreadList::cancel_finalize | ( | ) |
Cancel finalization on all threads.
Definition at line 599 of file thread_list.cpp.
References fawkes::LockList< Thread * >::lock().
void fawkes::ThreadList::clear | ( | ) |
Clear the list.
Removes all elements.
Definition at line 776 of file thread_list.cpp.
Referenced by ThreadList(), and fawkes::InterruptibleBarrier::wait().
ThreadList::iterator fawkes::ThreadList::erase | ( | iterator | pos | ) |
Erase element at given position.
pos | iterator marking the element to remove. |
Definition at line 839 of file thread_list.cpp.
void fawkes::ThreadList::finalize | ( | ThreadFinalizer * | finalizer | ) |
Finalize Threads.
The threads are finalized. This operation is carried out unlocked. Lock it from the outside if needed. This is done because it is likely that this will be chained with other actions that require locking, thus you can lock the whole operation.
finalizer | thread finalizer to use to finalize the threads |
Definition at line 565 of file thread_list.cpp.
References fawkes::Exception::append(), and fawkes::ThreadFinalizer::finalize().
Referenced by force_stop(), and init().
void fawkes::ThreadList::force_stop | ( | ThreadFinalizer * | finalizer | ) |
Force stop of all threads.
This will call prepare_finalize(), finalize(), cancel() and join() on the list without caring about the return values in the prepare_finalize() step.
finalizer | thread finalizer to use to finalize the threads. |
Definition at line 641 of file thread_list.cpp.
References finalize(), prepare_finalize(), and stop().
Referenced by fawkes::ThreadManager::force_remove().
void fawkes::ThreadList::init | ( | ThreadInitializer * | initializer, |
ThreadFinalizer * | finalizer | ||
) |
Initialize threads.
The threads are being initialized. This operation is carried out unlocked. Lock it from the outside if needed. This is done because it is likely that this will be chained with other actions that require locking, thus you can lock the whole operation.
initializer | thread initializer to use |
finalizer | finalizer to use to finalize threads that have been successfully initialized before one thread failed. |
CannotInitializeThreadException | thrown if at least one of the threads in this list could not be initialized. |
Definition at line 368 of file thread_list.cpp.
References fawkes::Exception::append(), fawkes::ThreadFinalizer::finalize(), finalize(), fawkes::ThreadInitializer::init(), and push_back().
void fawkes::ThreadList::join | ( | ) |
Join threads.
The threads are joined. This operation is carried out unlocked. Lock it from the outside if needed. This is done because it is likely that this will be chained with other actions that require locking, thus you can lock the whole operation.
Since errorneous behavior has been seen when run inside gdb something like
shout be avoided. Instead use
Definition at line 487 of file thread_list.cpp.
const char * fawkes::ThreadList::name | ( | ) |
Name of the thread list.
This can be used for better log output to identify the list that causes problems.
Definition at line 659 of file thread_list.cpp.
Referenced by fawkes::ThreadManager::force_remove(), and wakeup_and_wait().
ThreadList & fawkes::ThreadList::operator= | ( | const ThreadList & | tl | ) |
Assignment operator.
tl | thread list to assign |
Definition at line 149 of file thread_list.cpp.
void fawkes::ThreadList::pop_back | ( | ) |
Remove last element.
Definition at line 825 of file thread_list.cpp.
void fawkes::ThreadList::pop_front | ( | ) |
Remove first element.
Definition at line 814 of file thread_list.cpp.
bool fawkes::ThreadList::prepare_finalize | ( | ThreadFinalizer * | finalizer | ) |
Prepare finalize.
The threads are prepared for finalization. If any of the threads return false the whole list will return false. This operation is carried out unlocked. Lock it from the outside if needed. This is done because it is likely that this will be chained with other actions that require locking, thus you can lock the whole operation.
finalizer | thread finalizer to use to prepare finalization of the threads |
Definition at line 524 of file thread_list.cpp.
References fawkes::Exception::append(), fawkes::LockList< Thread * >::lock(), and fawkes::ThreadFinalizer::prepare_finalize().
Referenced by force_stop().
void fawkes::ThreadList::push_back | ( | Thread * | thread | ) |
Add thread to the end.
Add thread to the end of the list.
thread | thread to add |
Definition at line 744 of file thread_list.cpp.
Referenced by BallPosLogPlugin::BallPosLogPlugin(), BlackBoardLoggerPlugin::BlackBoardLoggerPlugin(), BlackBoardLogReplayPlugin::BlackBoardLogReplayPlugin(), BlackBoardSynchronizationPlugin::BlackBoardSynchronizationPlugin(), ExamplePlugin::ExamplePlugin(), FestivalPlugin::FestivalPlugin(), FlitePlugin::FlitePlugin(), FvBasePlugin::FvBasePlugin(), FvFountainPlugin::FvFountainPlugin(), FvRetrieverPlugin::FvRetrieverPlugin(), FvSrSavePlugin::FvSrSavePlugin(), init(), JoystickPlugin::JoystickPlugin(), KatanaPlugin::KatanaPlugin(), LaserFilterPlugin::LaserFilterPlugin(), LaserHoughTransformPlugin::LaserHoughTransformPlugin(), LaserPlugin::LaserPlugin(), LuaAgentPlugin::LuaAgentPlugin(), OpenRavePlugin::OpenRavePlugin(), PanTiltPlugin::PanTiltPlugin(), PlayerPlugin::PlayerPlugin(), push_back_locked(), ReadylogAgentPlugin::ReadylogAgentPlugin(), RefBoxCommPlugin::RefBoxCommPlugin(), RoombaJoystickPlugin::RoombaJoystickPlugin(), RoombaPlugin::RoombaPlugin(), ROSPlugin::ROSPlugin(), ROSTalkerPubPlugin::ROSTalkerPubPlugin(), ROSWebviewPlugin::ROSWebviewPlugin(), RRDExamplePlugin::RRDExamplePlugin(), RRDPlugin::RRDPlugin(), RRDWebPlugin::RRDWebPlugin(), SkillerPlugin::SkillerPlugin(), TimeTrackerMainLoopPlugin::TimeTrackerMainLoopPlugin(), wakeup_and_wait(), WebviewPlugin::WebviewPlugin(), WorldModelPlugin::WorldModelPlugin(), XabslPlugin::XabslPlugin(), and XmlRpcPlugin::XmlRpcPlugin().
void fawkes::ThreadList::push_back_locked | ( | Thread * | thread | ) |
Add thread to the end with lock protection.
Add thread to the end of the list. The operation is protected by the thread list lock. The operation will succeed without blocking even if the list is currently locked. It will push the thread to an internal temporary list and will add the thread finally when the list is unlocked.
thread | thread to add |
Definition at line 762 of file thread_list.cpp.
References fawkes::LockList< Thread * >::lock(), fawkes::LockList< Thread * >::mutex(), and push_back().
Referenced by fawkes::InterruptibleBarrier::wait().
void fawkes::ThreadList::push_front | ( | Thread * | thread | ) |
Add thread to the front.
Add thread to the beginning of the list.
thread | thread to add |
Definition at line 711 of file thread_list.cpp.
Referenced by push_front_locked().
void fawkes::ThreadList::push_front_locked | ( | Thread * | thread | ) |
Add thread to the front with lock protection.
Add thread to the beginning of the list. The operation is protected by the thread list lock. The operation will succeed without blocking even if the list is currently locked. It will push the thread to an internal temporary list and will add the thread finally when the list is unlocked.
thread | thread to add |
Definition at line 729 of file thread_list.cpp.
References fawkes::LockList< Thread * >::lock(), fawkes::LockList< Thread * >::mutex(), and push_front().
void fawkes::ThreadList::remove | ( | Thread * | thread | ) |
Remove with lock protection.
thread | thread to remove. |
Definition at line 789 of file thread_list.cpp.
Referenced by remove_locked().
void fawkes::ThreadList::remove_locked | ( | Thread * | thread | ) |
Remove with lock protection.
thread | thread to remove. |
Definition at line 802 of file thread_list.cpp.
References fawkes::LockList< Thread * >::lock(), fawkes::LockList< Thread * >::mutex(), and remove().
void fawkes::ThreadList::seal | ( | ) |
Seal the list.
Definition at line 700 of file thread_list.cpp.
bool fawkes::ThreadList::sealed | ( | ) |
Check if list is sealed.
If the list is sealed, no more writing operations are allowed and will trigger an exception.
Definition at line 692 of file thread_list.cpp.
Referenced by fawkes::ThreadManager::force_remove().
void fawkes::ThreadList::set_maintain_barrier | ( | bool | maintain_barrier | ) |
Set if this thread list should maintain a barrier.
This operation does an implicit locking of the list.
maintain_barrier | true to maintain an internal barrier, false to disable it. |
Definition at line 308 of file thread_list.cpp.
References fawkes::LockList< Thread * >::lock(), and fawkes::LockList< Thread * >::mutex().
void fawkes::ThreadList::set_name | ( | const char * | format, |
... | |||
) |
Set name of thread.
Use parameters similar to printf().
format | format string |
Definition at line 670 of file thread_list.cpp.
Referenced by fawkes::Plugin::set_name().
void fawkes::ThreadList::set_prepfin_hold | ( | bool | hold | ) |
Set prepfin hold on all threads.
This method will call Thread::set_prepfin_hold() for all threads in the list. If any of the threads fails to set prepfin hold then all thread were it has already been set are set to prepfin hold false.
hold | prepfin hold value |
Definition at line 617 of file thread_list.cpp.
void fawkes::ThreadList::start | ( | ) |
Start threads.
The threads are started. This operation is carried out unlocked. Lock it from the outside if needed. This is done because it is likely that this will be chained with other actions that require locking, thus you can lock the whole operation.
Definition at line 435 of file thread_list.cpp.
void fawkes::ThreadList::stop | ( | ) |
Stop threads.
The threads are canceled and joined. This operation is carried out unlocked. Lock it from the outside if needed. This is done because it is likely that this will be chained with other actions that require locking, thus you can lock the whole operation.
Definition at line 502 of file thread_list.cpp.
Referenced by force_stop().
void fawkes::ThreadList::try_recover | ( | std::list< std::string > & | recovered_threads | ) |
Check if any of the bad barriers recovered.
If the ThreadList maintains the barrier these may get bad if a thread does not finish in time. This method will check all bad barriers if the bad threads have recovered, and if so it will re-integrate the bad threads.
recovered_threads | upon return the names of any threads that could be recovered from a bad state have been added to the list. |
Definition at line 326 of file thread_list.cpp.
References fawkes::Thread::FLAG_BAD, fawkes::LockList< Thread * >::lock(), and fawkes::LockList< Thread * >::mutex().
void fawkes::ThreadList::wakeup | ( | ) |
Wakeup all threads in list.
Definition at line 164 of file thread_list.cpp.
References fawkes::LockList< Thread * >::lock(), and fawkes::LockList< Thread * >::mutex().
void fawkes::ThreadList::wakeup | ( | Barrier * | barrier | ) |
Wakeup all threads in list and have them wait for the barrier.
barrier | Barrier to wait for after loop |
Definition at line 191 of file thread_list.cpp.
References fawkes::LockList< Thread * >::lock(), and fawkes::LockList< Thread * >::mutex().
void fawkes::ThreadList::wakeup_and_wait | ( | unsigned int | timeout_sec = 0 , |
unsigned int | timeout_nanosec = 0 |
||
) |
Wakeup threads and wait for them to finish.
This assumes that all threads are in wait-for-wakeup mode. The threads are woken up with an internally maintained barrier. The method will return when all threads have finished one loop() iteration.
timeout_sec | timeout in seconds |
timeout_nanosec | timeout in nanoseconds |
NullPointerException | thrown, if no internal barrier is maintained. Make sure you use the proper constructor. |
Definition at line 247 of file thread_list.cpp.
References fawkes::Thread::FLAG_BAD, fawkes::LockList< Thread * >::lock(), fawkes::LockList< Thread * >::mutex(), name(), fawkes::InterruptibleBarrier::passed_threads(), push_back(), fawkes::InterruptibleBarrier::wait(), and wakeup_unlocked().
void fawkes::ThreadList::wakeup_unlocked | ( | ) |
Wakeup all threads in list.
This method wakes up all thread without acquiring the lock first. This method must only be used if the thread list is locked otherwise!
Definition at line 179 of file thread_list.cpp.
Referenced by wakeup_and_wait().
void fawkes::ThreadList::wakeup_unlocked | ( | Barrier * | barrier | ) |
Wakeup all threads in list and have them wait for the barrier.
This method wakes up all thread without aquiring the lock first. This method must only be used if the thread list is locked otherwise!
barrier | Barrier to wait for after loop |
Definition at line 207 of file thread_list.cpp.
References fawkes::Exception::append(), and fawkes::Barrier::count().