1 #ifndef _library_workthread__hpp__included__
2 #define _library_workthread__hpp__included__
5 #include "threadtypes.hpp"
7 #define WORKFLAG_QUIT_REQUEST 0x80000000U
9 class worker_thread_reflector
;
14 * Note: All methods (except entrypoints) are thread-safe.
26 virtual ~worker_thread();
28 * Request quit. Sets quit request workflag.
36 * Clear the busy flag.
40 * Wait until busy flag cleared.
44 * Rethrow caught exception if any.
50 * Parameter flag: The flags to set.
52 void set_workflag(uint32_t flag
);
56 * Parameter flag: Work flags to clear.
57 * Returns: The workflags before clearing.
59 uint32_t clear_workflag(uint32_t flag
);
61 * Wait until work flags nonzero.
63 * Returns: Current work flags.
65 uint32_t wait_workflag();
67 * Thread raw entrypoint.
69 * Note: Don't call from outside workthread code.
71 int operator()(int dummy
);
75 * Retrns: Two-element tuple.
76 * - The first element is the amount of microseconds wait_busy() has waited.
77 * - The second element is the amount of microseconds wait_workflag() has waited.
79 std::pair
<uint64_t, uint64_t> get_wait_count();
84 * Notes: Exceptions thrown are catched.
86 virtual void entry() = 0;
88 * Start actually running the thread.
93 worker_thread_reflector
* reflector
;
97 volatile uint32_t workflag
;
99 volatile bool exception_caught
;
100 volatile bool exception_oom
;
101 volatile uint64_t waitamt_busy
;
102 volatile uint64_t waitamt_work
;
103 std::string exception_text
;