feat(el): Expose the EventLoop mutex in its API

This commit is contained in:
Julius Pfrommer
2025-01-25 19:14:35 +01:00
committed by Julius Pfrommer
parent f691be7cca
commit b1151d37b7
2 changed files with 27 additions and 0 deletions
+15
View File
@@ -417,6 +417,18 @@ UA_EventLoopPOSIX_free(UA_EventLoopPOSIX *el) {
return UA_STATUSCODE_GOOD;
}
static void
UA_EventLoopPOSIX_lock(UA_EventLoop *public_el) {
UA_EventLoopPOSIX *el = (UA_EventLoopPOSIX*)public_el;
UA_LOCK(&el->elMutex);
}
static void
UA_EventLoopPOSIX_unlock(UA_EventLoop *public_el) {
UA_EventLoopPOSIX *el = (UA_EventLoopPOSIX*)public_el;
UA_UNLOCK(&el->elMutex);
}
UA_EventLoop *
UA_EventLoop_new_POSIX(const UA_Logger *logger) {
UA_EventLoopPOSIX *el = (UA_EventLoopPOSIX*)
@@ -462,6 +474,9 @@ UA_EventLoop_new_POSIX(const UA_Logger *logger) {
(UA_StatusCode (*)(UA_EventLoop*, UA_EventSource*))
UA_EventLoopPOSIX_deregisterEventSource;
el->eventLoop.lock = UA_EventLoopPOSIX_lock;
el->eventLoop.unlock = UA_EventLoopPOSIX_unlock;
return &el->eventLoop;
}
+12
View File
@@ -198,6 +198,18 @@ struct UA_EventLoop {
/* Stops the EventSource before deregistrering it */
UA_StatusCode
(*deregisterEventSource)(UA_EventLoop *el, UA_EventSource *es);
/* Locking
* ~~~~~~~
*
* For multi-threading the EventLoop is protected by a mutex. The mutex is
* expected to be recursive (can be taken more than once from the same
* thread). A common approach to avoid deadlocks is to establish an absolute
* ordering between the locks. Where the "lower" locks needs to be taken
* before the "upper" lock. The EventLoop-mutex is exposed here to allow it
* to be taken from the outside. */
void (*lock)(UA_EventLoop *el);
void (*unlock)(UA_EventLoop *el);
};
/**