Fawkes API
Fawkes Development Version
|
24 #ifndef _CORE_THREADING_THREAD_H_
25 #define _CORE_THREADING_THREAD_H_
27 #include <sys/types.h>
32 #define forever while (1)
39 class ThreadNotificationListener;
40 class ThreadLoopListener;
42 template <
typename Type>
79 void start(
bool wait =
true);
144 void set_name(const
char *format, ...);
159 static
void *entry(
void *pthis);
160 void __constructor(const
char *
name,
OpMode op_mode);
161 void notify_of_startup();
162 void lock_sleep_mutex();
164 static
void init_thread_key();
165 static
void set_tsd_thread_instance(
Thread *t);
167 pthread_t thread_id_;
170 mutable
Mutex *sleep_mutex_;
172 unsigned int pending_wakeups_;
176 Mutex * loop_done_mutex_;
180 Mutex * prepfin_hold_mutex_;
186 bool waiting_for_wakeup_;
187 bool delete_on_exit_;
192 bool prepfin_conc_loop_;
193 bool coalesce_wakeups_;
201 static pthread_key_t THREAD_KEY;
202 static pthread_key_t MAIN_THREAD_KEY;
203 static pthread_mutex_t thread_key_mutex_;
void set_delete_on_exit(bool del)
Set whether the thread should be deleted on exit.
static void init_main()
Initialize Thread wrapper instance for main thread.
virtual void loop()
Code to execute in the thread.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
void kill(int sig)
Send signal to a thread.
virtual void finalize()
Finalize the thread.
@ CANCEL_ENABLED
cancellation is possible
static pthread_t current_thread_id()
Get the ID of the currently running thread.
void notify_of_failed_init()
Notify of failed init.
void remove_notification_listener(ThreadNotificationListener *notification_listener)
Remove notification listener.
void set_flag(uint32_t flag)
Set flag for the thread.
void wakeup()
Wake up thread.
static Thread * current_thread()
Get the Thread instance of the currently running thread.
@ OPMODE_CONTINUOUS
operate in continuous mode (default)
virtual void once()
Execute an action exactly once.
void yield()
Yield the processor to another thread or process.
void add_loop_listener(ThreadLoopListener *loop_listener)
Add loop listener.
const char * name() const
static std::string current_thread_name()
Get the name of the current thread.
void test_cancel()
Set cancellation point.
bool prepare_finalize()
Prepare finalization.
static void destroy_main()
Destroy main thread wrapper instance.
void cancel_finalize()
Cancel finalization.
pthread_t thread_id() const
Get ID of thread.
void exit()
Exit the thread.
virtual ~Thread()
Virtual destructor.
bool detached() const
Check if thread has been detached.
bool running() const
Check if the thread is running.
void set_coalesce_wakeups(bool coalesce=true)
Set wakeup coalescing.
static Thread * current_thread_noexc()
Similar to current_thread, but does never throw an exception.
void detach()
Detach the thread.
bool cancelled() const
Check if thread has been cancelled.
@ CANCEL_DISABLED
thread cannot be cancelled
@ OPMODE_WAITFORWAKEUP
operate in wait-for-wakeup mode
virtual void init()
Initialize the thread.
void set_flags(uint32_t flags)
Set all flags in one go.
bool operator==(const Thread &thread)
Check if two threads are the same.
void add_notification_listener(ThreadNotificationListener *notification_listener)
Add notification listener.
Mutex * loopinterrupt_antistarve_mutex
bool started() const
Check if thread has been started.
void wait_loop_done()
Wait for the current loop iteration to finish.
virtual void run()
Code to execute in the thread.
virtual bool prepare_finalize_user()
Prepare finalization user implementation.
OpMode opmode() const
Get operation mode.
void unset_flag(uint32_t flag)
Unset flag.
void start(bool wait=true)
Call this method to start the thread.
static void set_cancel_state(CancelState new_state, CancelState *old_state=0)
Set the cancel state of the current thread.
OpMode
Thread operation mode.
void cancel()
Cancel a thread.
void remove_loop_listener(ThreadLoopListener *loop_listener)
Remove loop listener.
void set_opmode(OpMode op_mode)
Set operation mode.
bool flagged_bad() const
Check if FLAG_BAD was set.
bool wakeup_pending()
Check if wakeups are pending.
void set_name(const char *format,...)
Set name of thread.
bool waiting() const
Check if thread is currently waiting for wakeup.
void join()
Join the thread.
void set_prepfin_hold(bool hold)
Hold prepare_finalize().
static const unsigned int FLAG_BAD
Standard thread flag: "thread is bad".