MXS-1754 Add possibility to cancel delayed calls
The interface for canceling calls is now geared towards the needs of sessions. Basically the idea is as follows: class MyFilterSession : public maxscale::FilterSession { ... int MyFilterSession::routeQuery(GWBUF* pPacket) { ... if (needs_to_be_delayed()) { Worker* pWorker = Worker::current(); void* pTag = this; pWorker->delayed_call(5000, pTag, this, &MyFilterSession::delayed_routeQuery, pPacket); return 1; } ... } bool MyFilterSession::delayed_routeQuery(Worker::Call:action_t action, GWBUF* pPacket) { if (action == Worker::Call::EXECUTE) { routeQuery(pPacket); } else { ss_dassert(action == Worker::Call::CANCEL); gwbuf_free(pPacket); } return false; } ~MyFilterSession() { void* pTag = this; Worker::current()->cancel_delayed_calls(pTag); } } The alternative, returning some key that the caller must keep around seems more cumbersome for the general case.
This commit is contained in:
@ -1138,7 +1138,7 @@ void Worker::tick()
|
||||
pDelayed_call = m_delayed_calls.top();
|
||||
m_delayed_calls.pop();
|
||||
|
||||
if (pDelayed_call->call())
|
||||
if (pDelayed_call->call(Worker::Call::EXECUTE))
|
||||
{
|
||||
repeating_calls.push_back(pDelayed_call);
|
||||
}
|
||||
@ -1203,6 +1203,13 @@ void Worker::adjust_timer()
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Worker::cancel_delayed_calls(intptr_t tag)
|
||||
{
|
||||
// TODO: Implement
|
||||
ss_dassert(!true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user