30template<
typename Execution_context>
34 using boost::asio::post;
35 using boost::asio::dispatch;
90 FLOW_LOG_TRACE(
"About to post task via boost.asio execution context (Task_engine or Strand as of this writing) "
91 "[@" << exec_ctx <<
"]; might sync-execute in this thread? = "
93 "will we ensure concurrent completion before continuing? = "
95 "will we ensure concurrent initiation before continuing? = "
98 Task actual_task(std::move(task));
102 if (logger_ptr && logger_ptr->
should_log(Sev::S_TRACE, get_log_component()))
104 actual_task = [get_logger, get_log_component, wrapped_task = std::move(actual_task)]()
118 post(*exec_ctx, std::move(actual_task));
123 dispatch(*exec_ctx, std::move(actual_task));
130 &&
"asio_exec_ctx_post() failed to handle one of the Synchronicity enum values.");
139 FLOW_LOG_TRACE(
"From outside thread pool, we post task to execute concurrently; and await its "
140 "[" << (assure_finish_else_start ?
"completion" :
"initiation") <<
"]. "
141 "A deadlock here implies bug, namely that we are *not* outside thread pool now after all.");
143 promise<void> wait_done_promise;
145 if (assure_finish_else_start)
147 post(*exec_ctx, [&]()
150 wait_done_promise.set_value();
155 post(*exec_ctx, [&wait_done_promise,
156 actual_task = std::move(actual_task)]
159 wait_done_promise.set_value();
164 wait_done_promise.get_future().wait();
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
virtual bool should_log(Sev sev, const Component &component) const =0
Given attributes of a hypothetical message that would be logged, return true if that message should b...
#define FLOW_LOG_SET_CONTEXT(ARG_logger_ptr, ARG_component_payload)
For the rest of the block within which this macro is instantiated, causes all FLOW_LOG_....
#define FLOW_LOG_TRACE(ARG_stream_fragment)
Logs a TRACE message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
Flow module containing tools enabling multi-threaded event loops operating under the asynchronous-tas...
Synchronicity
Enumeration indicating the manner in which asio_exec_ctx_post(), and various boost....
@ S_ASYNC
Simply post the given task to execute asynchronously in some execution context – as soon as the conte...
@ S_ASYNC_AND_AWAIT_CONCURRENT_COMPLETION
Same as Synchronicity::S_ASYNC but the posting routine then waits as long as necessary for the given ...
@ S_ASYNC_AND_AWAIT_CONCURRENT_START
Same as Synchronicity::S_ASYNC but the posting routine then waits as long as necessary for the given ...
@ S_OPPORTUNISTIC_SYNC_ELSE_ASYNC
Execute the given task synchronously, if the scheduler determines that the calling thread is in its t...
void asio_exec_ctx_post(log::Logger *logger_ptr, Execution_context *exec_ctx, Synchronicity synchronicity, Task &&task)
An extension of boost.asio's post() and dispatch() free function templates, this free function templa...
uint16_t cpu_idx()
Returns the 0-based processor logical (not hardware) core index of the core executing the calling thr...
Sev
Enumeration containing one of several message severity levels, ordered from highest to lowest.