cluster/ThreadedBackend: Invoke onloop->Process() during DoTerminate()

Also, document how to use ThreadedBackend's DoTerminate()
This commit is contained in:
Arne Welzel 2025-04-24 09:02:08 +02:00
parent 85a2694cb2
commit eb2eaee284
2 changed files with 14 additions and 1 deletions

View file

@ -203,6 +203,7 @@ bool ThreadedBackend::DoInit() {
void ThreadedBackend::DoTerminate() {
if ( onloop ) {
onloop->Process();
onloop->Close();
onloop = nullptr;
}

View file

@ -564,7 +564,8 @@ protected:
/**
* To be used by implementations to enqueue messages for processing on the IO loop.
*
* It's safe to call this method from any thread.
* It's safe to call this method from any thread before ThreadedBackend's
* DoTerminate() implementation is invoked.
*
* @param messages Messages to be enqueued.
*/
@ -582,6 +583,17 @@ protected:
*/
bool DoInit() override;
/**
* Common DoTerminate() functionality for threaded backends.
*
* The default DoTerminate() implementation of ThreadedBackend
* runs OnLoop's Process() once to drain any pending messages, then
* closes and unsets it.
*
* Classes deriving from ThreadedBackend need to ensure that all threads
* calling QeueuForProcessing() have terminated before invoking the
* ThreadedBackend's DoTerminate() implementation.
*/
void DoTerminate() override;
private: