mirror of
https://github.com/open62541/open62541.git
synced 2026-10-19 14:22:58 +08:00
feat(el): Expose the EventLoop mutex in its API
This commit is contained in:
committed by
Julius Pfrommer
parent
f691be7cca
commit
b1151d37b7
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user