MXS-2467 Allow 0-delay delayed calls

A 0-delay delayed call simply means that it will be invoked as
quickly as possible.
This commit is contained in:
Johan Wikman
2019-05-03 13:33:57 +03:00
parent fb0745e3de
commit d498f1042c

View File

@ -780,17 +780,27 @@ private:
// delay is very short and the execution time for the function very long, // delay is very short and the execution time for the function very long,
// then we will not succeed with that and the function will simply be // then we will not succeed with that and the function will simply be
// invoked as frequently as possible. // invoked as frequently as possible.
m_at += m_delay; int64_t now = WorkerLoad::get_time_ms();
int64_t then = m_at + m_delay;
if (now > then)
{
m_at = now;
}
else
{
m_at = then;
}
return rv; return rv;
} }
protected: protected:
DelayedCall(int32_t delay, int32_t id) DelayedCall(int32_t delay, int32_t id)
: m_id(id) : m_id(id)
, m_delay(delay) , m_delay(delay >= 0 ? delay : 0)
, m_at(get_at(delay)) , m_at(get_at(m_delay))
{ {
mxb_assert(delay > 0); mxb_assert(delay >= 0);
} }
virtual bool do_call(Worker::Call::action_t action) = 0; virtual bool do_call(Worker::Call::action_t action) = 0;
@ -798,13 +808,11 @@ private:
private: private:
static int64_t get_at(int32_t delay) static int64_t get_at(int32_t delay)
{ {
mxb_assert(delay > 0); mxb_assert(delay >= 0);
struct timespec ts; int64_t now = WorkerLoad::get_time_ms();
MXB_AT_DEBUG(int rv = ) clock_gettime(CLOCK_MONOTONIC, &ts);
mxb_assert(rv == 0);
return delay + (ts.tv_sec * 1000 + ts.tv_nsec / 1000000); return now + delay;
} }
private: private: