Skip to content

Commit

Permalink
feat(el): Add removeDelayedCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Sep 7, 2022
1 parent f3a8c08 commit f542690
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 17 additions & 0 deletions arch/eventloop_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ UA_EventLoopPOSIX_addDelayedCallback(UA_EventLoop *public_el,
UA_UNLOCK(&el->elMutex);
}

static void
UA_EventLoopPOSIX_removeDelayedCallback(UA_EventLoop *public_el,
UA_DelayedCallback *dc) {
UA_EventLoopPOSIX *el = (UA_EventLoopPOSIX*)public_el;
UA_LOCK(&el->elMutex);
UA_DelayedCallback **prev = &el->delayedCallbacks;
while(*prev) {
if(*prev == dc) {
*prev = (*prev)->next;
return;
}
prev = &(*prev)->next;
}
UA_UNLOCK(&el->elMutex);
}

/* Process and then free registered delayed callbacks */
static void
processDelayed(UA_EventLoopPOSIX *el) {
Expand Down Expand Up @@ -423,6 +439,7 @@ UA_EventLoop_new_POSIX(const UA_Logger *logger) {
el->eventLoop.modifyCyclicCallback = UA_EventLoopPOSIX_modifyCyclicCallback;
el->eventLoop.removeCyclicCallback = UA_EventLoopPOSIX_removeCyclicCallback;
el->eventLoop.addDelayedCallback = UA_EventLoopPOSIX_addDelayedCallback;
el->eventLoop.removeDelayedCallback = UA_EventLoopPOSIX_removeDelayedCallback;

el->eventLoop.registerEventSource =
(UA_StatusCode (*)(UA_EventLoop*, UA_EventSource*))
Expand Down
12 changes: 9 additions & 3 deletions include/open62541/plugin/eventloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,18 @@ struct UA_EventLoop {

/* Delayed Callbacks
* ~~~~~~~~~~~~~~~~~
* The registered delayed callbacks are executed once in each cycle of the
* EventLoop (between the cyclic callbacks and polling for events with a
* timeout). The memory for the delayed callback is freed after the
* Delayed callbacks are executed once by the EventLoop and then
* deregistered automatically. A typical use case is to delay a resource
* cleanup to a point where it is known that the resource has no remaining
* users "upwards in the call stack".
*
* The execution happens in the cycle of the EventLoop between the handling
* of timed cyclic callbacks and polling for (network) events. The memory
* for the delayed callback is NOT automatically freed after the
* execution. */

void (*addDelayedCallback)(UA_EventLoop *el, UA_DelayedCallback *dc);
void (*removeDelayedCallback)(UA_EventLoop *el, UA_DelayedCallback *dc);

/* EventSources
* ~~~~~~~~~~~~
Expand Down

0 comments on commit f542690

Please sign in to comment.