-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement auto invocation of deferred slots
Connection invocations are now evaluated automatically in the event loop. Any time an invocation is enqueued using the event loop's connection evaluator, the event loop is woken up. This required a KDUtils-specific ConnectionEvaluator. When given event loop is destroyed, it sets a reference in the evaluator to null. It's a defensive measure for the future to prevent misuse of lingering evaluators in case the user deletes the event loop first. AbstractEventLoop::waitForEvents is not pure abstract anymore as it ensures evaluation of slot invocations. Removed one copypasted comment in android event loop impl.
- Loading branch information
Showing
16 changed files
with
123 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/KDFoundation/platform/abstract_platform_event_loop.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
This file is part of KDUtils. | ||
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
Author: Miłosz Kosobucki <[email protected]> | ||
SPDX-License-Identifier: MIT | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
#include <KDFoundation/platform/abstract_platform_event_loop.h> | ||
#include "abstract_platform_event_loop.h" | ||
|
||
namespace KDFoundation { | ||
|
||
/** | ||
* KDUtils-specific connection evaluator that wakes up the owning event loop when slot invocation is | ||
* enqueued via the loop's connection evaluator. | ||
*/ | ||
class ConnectionEvaluator final : public KDBindings::ConnectionEvaluator | ||
{ | ||
public: | ||
ConnectionEvaluator(AbstractPlatformEventLoop *eventLoop) | ||
: m_eventLoop(eventLoop) { } | ||
|
||
void setEventLoop(AbstractPlatformEventLoop *eventLoop) | ||
{ | ||
this->m_eventLoop = eventLoop; | ||
} | ||
|
||
protected: | ||
void onInvocationAdded() override | ||
{ | ||
if (m_eventLoop) { | ||
m_eventLoop->wakeUp(); | ||
} | ||
} | ||
|
||
private: | ||
AbstractPlatformEventLoop *m_eventLoop = nullptr; | ||
}; | ||
} // namespace KDFoundation | ||
|
||
using namespace KDFoundation; | ||
|
||
KDFoundation::AbstractPlatformEventLoop::AbstractPlatformEventLoop() | ||
: m_connectionEvaluator(new ConnectionEvaluator(this)) | ||
{ | ||
} | ||
|
||
AbstractPlatformEventLoop::~AbstractPlatformEventLoop() | ||
{ | ||
// Make sure that any remaining references to our connection evaluator aren't referring to a dead | ||
// event loop object. | ||
if (m_connectionEvaluator) { | ||
std::static_pointer_cast<KDFoundation::ConnectionEvaluator>(m_connectionEvaluator)->setEventLoop(nullptr); | ||
} | ||
} | ||
|
||
void KDFoundation::AbstractPlatformEventLoop::waitForEvents(int timeout) | ||
{ | ||
waitForEventsImpl(timeout); | ||
|
||
// Possibly we woke up because of deferred slot invocation was posted. Let's (possibly) | ||
// execute them while we're at it. | ||
if (m_connectionEvaluator) { | ||
m_connectionEvaluator->evaluateDeferredConnections(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters