28 using boost::chrono::round;
29 using boost::chrono::milliseconds;
34 auto& timer = task->m_timer;
35 const bool single_threaded = !task->m_mutex_unless_single_threaded;
40 auto cancel_if_should = [&]() ->
bool
45 "that was set to fire in [" << round<milliseconds>(timer.expires_from_now()) <<
"]; "
46 "single-threaded optimizations applicable? = [" << single_threaded <<
"].");
50 FLOW_LOG_TRACE(
"Was going to cancel but user handler already began executing earlier. Done.");
56 FLOW_LOG_TRACE(
"Was going to cancel but task was already canceled earlier. Done.");
60 task->m_canceled =
true;
70 catch (
const system_error& exc)
83 canceled = cancel_if_should();
88 canceled = cancel_if_should();
97 using boost::asio::post;
98 using boost::chrono::round;
99 using boost::chrono::milliseconds;
107 auto& timer = task->m_timer;
108 const bool single_threaded = !task->m_mutex_unless_single_threaded;
114 auto fire_if_should = [&]()
116 FLOW_LOG_TRACE(
"Short-firing scheduled task [" << task->m_id <<
"] "
117 "that was set to fire in [" << round<milliseconds>(timer.expires_from_now()) <<
"]; "
118 "single-threaded optimizations applicable? = [" << single_threaded <<
"].");
122 FLOW_LOG_TRACE(
"Was going to short-fire but user handler already began executing earlier. Done.");
126 if (task->m_canceled)
128 FLOW_LOG_TRACE(
"Was going to short-fire but task was already canceled earlier. Done.");
132 task->m_fired =
true;
145 catch (
const system_error& exc)
157 noop = !fire_if_should();
162 noop = !fire_if_should();
174 post(*task->m_task_engine, [get_logger, get_log_component, task]()
176 const bool single_threaded = !task->m_mutex_unless_single_threaded;
178 FLOW_LOG_TRACE(
"Short-executing recently-short-fired scheduled task [" << task->m_id <<
"]; "
179 "single-threaded optimizations applicable? = [" << single_threaded <<
"].");
184 assert(task->m_fired && (!task->m_canceled));
188 Lock_guard<Mutex_non_recursive> lock(*task->m_mutex_unless_single_threaded);
189 assert(task->m_fired && (!task->m_canceled));
193 (task->m_body)(
true);
194 FLOW_LOG_TRACE(
"Short-fired scheduled task [" << task->m_id <<
"]: Body-post()ing function finished.");
202 using boost::chrono::milliseconds;
203 using boost::chrono::round;
209 if (task->m_canceled)
211 FLOW_LOG_TRACE(
"Scheduled task [" << task->m_id <<
"]: Returning special value for fires-from-now because "
213 return Fine_duration::max();
216 const auto& from_now = task->m_timer.expires_from_now();
217 FLOW_LOG_TRACE(
"Scheduled task [" << task->m_id <<
"]: Returning fires-from-now value "
218 "[" << round<milliseconds>(from_now) <<
"].");
223 const auto& mtx = task->m_mutex_unless_single_threaded;
242 const auto do_it = [&]() ->
bool
244 const bool is_it = task->m_fired;
245 FLOW_LOG_TRACE(
"Scheduled task [" << task->m_id <<
"]: Returning fired? = [" << is_it <<
"].");
249 const auto& mtx = task->m_mutex_unless_single_threaded;
263 const auto do_it = [&]() ->
bool
265 const bool is_it = task->m_canceled;
266 FLOW_LOG_TRACE(
"Scheduled task [" << task->m_id <<
"]: Returning canceled? = [" << is_it <<
"].");
270 const auto& mtx = task->m_mutex_unless_single_threaded;
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
#define FLOW_ERROR_SYS_ERROR_LOG_WARNING()
Logs a warning about the (often errno-based or from a library) error code in sys_err_code.
#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 miscellaneous general-use facilities that don't fit into any other Flow module...
boost::unique_lock< Mutex > Lock_guard
Short-hand for advanced-capability RAII lock guard for any mutex, ensuring exclusive ownership of tha...
bool scheduled_task_fired(log::Logger *logger_ptr, Scheduled_task_const_handle task)
Returns whether a previously scheduled (by schedule_task_from_now() or similar) task has already fire...
Fine_duration scheduled_task_fires_from_now_or_canceled(log::Logger *logger_ptr, Scheduled_task_const_handle task)
Returns how long remains until a previously scheduled (by schedule_task_from_now() or similar) task f...
boost::shared_ptr< Scheduled_task_handle_state > Scheduled_task_handle
Black-box type that represents a handle to a scheduled task as scheduled by schedule_task_at() or sch...
bool scheduled_task_short_fire(log::Logger *logger_ptr, Scheduled_task_handle task)
Attempts to reschedule a previously scheduled (by schedule_task_from_now() or similar) task to fire i...
bool scheduled_task_canceled(log::Logger *logger_ptr, Scheduled_task_const_handle task)
Returns whether a previously scheduled (by schedule_task_from_now() or similar) task has been cancele...
bool scheduled_task_cancel(log::Logger *logger_ptr, Scheduled_task_handle task)
Attempts to prevent the execution of a previously scheduled (by schedule_task_from_now() or similar) ...
boost::shared_ptr< const Scheduled_task_handle_state > Scheduled_task_const_handle
Equivalent to Scheduled_task_handle but refers to immutable version of a task.
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...
Fine_clock::duration Fine_duration
A high-res time duration as computed from two Fine_time_pts.