1 #ifndef _library_workthread__hpp__included__
2 #define _library_workthread__hpp__included__
10 * Note: All methods (except entrypoints) are thread-safe.
16 * Standard quit request.
18 static const uint32_t quit_request
;
26 virtual ~workthread();
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.
92 threads::thread
* thread
;
95 int operator()(workthread
* x
);
97 reflector
* _reflector
;
98 threads::cv condition
;
100 volatile bool joined
;
101 volatile uint32_t workflag
;
103 volatile bool exception_caught
;
104 volatile bool exception_oom
;
105 volatile uint64_t waitamt_busy
;
106 volatile uint64_t waitamt_work
;
107 std::string exception_text
;