Fawkes API
Fawkes Development Version
|
#include <>>
Public Member Functions | |
ThreadManager () | |
Constructor. More... | |
ThreadManager (ThreadInitializer *initializer, ThreadFinalizer *finalizer) | |
Constructor. More... | |
virtual | ~ThreadManager () |
Destructor. More... | |
void | set_inifin (ThreadInitializer *initializer, ThreadFinalizer *finalizer) |
Set initializer/finalizer. More... | |
virtual void | add (ThreadList &tl) |
virtual void | add (Thread *t) |
virtual void | remove (ThreadList &tl) |
virtual void | remove (Thread *t) |
virtual void | force_remove (ThreadList &tl) |
Force removal of the given threads. More... | |
virtual void | force_remove (Thread *t) |
Force removal of the given thread. More... | |
virtual void | wakeup_and_wait (BlockedTimingAspect::WakeupHook hook, unsigned int timeout_usec=0) |
virtual void | wakeup (BlockedTimingAspect::WakeupHook hook, Barrier *barrier=0) |
virtual void | try_recover (std::list< std::string > &recovered_threads) |
virtual bool | timed_threads_exist () |
virtual void | wait_for_timed_threads () |
virtual void | interrupt_timed_thread_wait () |
ThreadCollector * | aspect_collector () const |
Get a thread collector to be used for an aspect initializer. More... | |
![]() | |
virtual | ~ThreadCollector () |
Empty virtual destructor. More... | |
![]() | |
virtual | ~BlockedTimingExecutor () |
Virtual empty destructor. More... | |
Base application thread manager. This class provides a manager for the threads. Threads are memorized by their wakeup hook. When the thread manager is deleted, all threads are appropriately cancelled, joined and deleted. Thus the thread manager can be used for "garbage collection" of threads.
The thread manager allows easy wakeup of threads of a given wakeup hook.
The thread manager needs a thread initializer. Each thread that is added to the thread manager is initialized with this. The runtime type information (RTTI) supplied by C++ can be used to initialize threads if appropriate (if the thread has certain aspects that need special treatment).
Definition at line 48 of file thread_manager.h.
fawkes::ThreadManager::ThreadManager | ( | ) |
Constructor.
When using this constructor you need to make sure to call set_inifin() before any thread is added.
Definition at line 140 of file thread_manager.cpp.
fawkes::ThreadManager::ThreadManager | ( | ThreadInitializer * | initializer, |
ThreadFinalizer * | finalizer | ||
) |
Constructor.
This contsructor is equivalent to the one without parameters followed by a call to set_inifins().
initializer | thread initializer |
finalizer | thread finalizer |
Definition at line 156 of file thread_manager.cpp.
|
virtual |
Destructor.
Definition at line 168 of file thread_manager.cpp.
|
inlinevirtual |
Add single thread. Adds the single thread to the internal (implementation specific) thread list. The thread is started if and only if initialization suceeds. A CannotInitializeThreadException is thrown if initialization failed.
t | thread to add |
Implements fawkes::ThreadCollector.
Definition at line 64 of file thread_manager.h.
|
inlinevirtual |
Add multiple threads. Adds all the threads in the list to the thread list. Implementations may throw an exception if this fails for whatever reason, read implementation documentation for details. The operation shall be atomic, either all threads are added successfully or none is added at all. If adding fails a CannotInitializeThreadException is thrown.
The thread is started if and only if initialization of all threads suceeds. A CannotInitializeThreadException is thrown if initialization failed for any thread.
tl | list of threads to add |
Implements fawkes::ThreadCollector.
Definition at line 58 of file thread_manager.h.
ThreadCollector * fawkes::ThreadManager::aspect_collector | ( | ) | const |
Get a thread collector to be used for an aspect initializer.
Definition at line 618 of file thread_manager.cpp.
|
virtual |
Force removal of the given thread.
The thread manager tries to finalize and stop the thread and then removes the thread from the internal structures.
This will succeed even if the thread cannot be finalized, for example if prepare_finalize() returns false or if the thread finalizer cannot finalize the thread.
Caution, using this function may damage your robot.
thread | thread to remove. |
ThreadListNotSealedException | if the given thread lits tl is not sealed the thread manager will refuse to remove it The threads are removed from thread manager control. The threads will be stopped before they are removed (may cause unpredictable results otherwise). |
Implements fawkes::ThreadCollector.
Definition at line 528 of file thread_manager.cpp.
|
virtual |
Force removal of the given threads.
The thread manager tries to finalize and stop the threads and then removes the threads from the internal structures.
This will succeed even if a thread of the given list cannot be finalized, for example if prepare_finalize() returns false or if the thread finalizer cannot finalize the thread.
Caution, using this function may damage your robot.
tl | threads to remove. |
ThreadListNotSealedException | if the given thread lits tl is not sealed the thread manager will refuse to remove it The threads are removed from thread manager control. The threads will be stopped before they are removed (may cause unpredictable results otherwise). |
Implements fawkes::ThreadCollector.
Definition at line 483 of file thread_manager.cpp.
|
virtual |
Interrupt any currently running wait_for_timed_threads() and cause it to throw an InterruptedException.
Implements fawkes::BlockedTimingExecutor.
Definition at line 608 of file thread_manager.cpp.
|
inlinevirtual |
Remove single thread. Remove the thread from the internal thread list. If the thread has never been collected no error shall be thrown but just be silently ignored. The thread is finalized, cancelled and joined. If the finalization fails for whatever reason the thread is NOT cancelled or stopped. In that case a CannotFinalizeThreadException is thrown.
t | Thread to remove. |
Implements fawkes::ThreadCollector.
Definition at line 76 of file thread_manager.h.
|
inlinevirtual |
Remove multiple threads. Remove all threads in the thread list from this collector. If there is a thread in the supplied thread list that has never been collected no error shall be thrown but this just be silently ignored.
The threads are finalized, cancelled and joined. If the finalization fails for whatever reason the threads are NOT cancelled or stopped. In that case a CannotFinalizeThreadException is thrown.
tl | list of threads to remove |
Implements fawkes::ThreadCollector.
Definition at line 70 of file thread_manager.h.
void fawkes::ThreadManager::set_inifin | ( | ThreadInitializer * | initializer, |
ThreadFinalizer * | finalizer | ||
) |
Set initializer/finalizer.
This method has to be called before any thread is added/removed.
initializer | thread initializer |
finalizer | thread finalizer |
Definition at line 194 of file thread_manager.cpp.
References fawkes::BlockedTimingAspect::blockedTimingAspectHook(), and fawkes::ThreadList::remove_locked().
|
virtual |
Check if any timed threads exist.
Implements fawkes::BlockedTimingExecutor.
Definition at line 591 of file thread_manager.cpp.
References fawkes::WaitCondition::wait().
|
virtual |
Try to recover threads. An advanced BlockedTimingExecutor might be able to detect deadlocked threads. In this case this function should be called regularly to allow for recovering threads that are back to normal operation.
recovered_threads | upon return the names of any threads that could be recovered from a bad state have been added to the list. |
Implements fawkes::BlockedTimingExecutor.
Definition at line 581 of file thread_manager.cpp.
|
virtual |
Wait for timed threads. Use this method to wait until a timed that is added to the thread manager. Note that an InterruptedException is thrown if interrup_timed_thread_wait() is called from another thread. You should catch this exception and stop the loop execution.
InterruptedException | thrown if another thread calls interrupt_timed_thread_wait() |
Implements fawkes::BlockedTimingExecutor.
Definition at line 597 of file thread_manager.cpp.
|
virtual |
Wakeup thread for given hook. This will wakeup all threads registered for the given hook. With the optional barrier you can synchronize to the end of the loop execution of the threads of the given hook.
hook | hook for which to wait for |
barrier | optional barrier that can be used to synchronize to the end of the loop execution of the threads. |
Implements fawkes::BlockedTimingExecutor.
Definition at line 564 of file thread_manager.cpp.
|
virtual |
Wakeup thread for given hook and wait for completion. This will wakeup all threads registered for the given hook. Afterwards this method will block until all threads finished their loop.
hook | hook for which to wait for |
timeout_usec | timeout for thread execution in usec. 0 disables the timeout and makes this function to wait forever. |
Exception | thrown if the timeout was exceeded (at least one of the threads for the given hook took longer than the desired time. |
Implements fawkes::BlockedTimingExecutor.
Definition at line 547 of file thread_manager.cpp.