From 05cf5b4b559d7c9dd1b5b1061a3b591907989e79 Mon Sep 17 00:00:00 2001 From: Lev Brouk Date: Sun, 3 Nov 2024 14:25:43 -0800 Subject: [PATCH] adjustments, +1 --- src/micro.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/micro.c b/src/micro.c index 1ad6e0f0..faac139c 100644 --- a/src/micro.c +++ b/src/micro.c @@ -350,6 +350,7 @@ microService_Stop(microService *m) return _stop_service(m, true, false); } +// service lock must be held by the caller. static void _detach_endpoint_from_service(microService *m, microEndpoint *toRemove) { @@ -359,18 +360,19 @@ _detach_endpoint_from_service(microService *m, microEndpoint *toRemove) if ((m == NULL) || (toRemove == NULL)) return; - for (ep = m->first_ep; ep != NULL; ep = ep->next) + for (ep = m->first_ep; (ep != NULL) && (ep != toRemove); prev_ep = ep, ep = ep->next) + ; + if (ep == NULL) + return; + + m->numEndpoints--; + if (prev_ep == NULL) + m->first_ep = ep->next; + else { - if (ep == toRemove) - { - m->numEndpoints--; - if (prev_ep == NULL) - m->first_ep = ep->next; - else - prev_ep->next = ep->next; - return; - } - prev_ep = ep; + micro_lock_endpoint(prev_ep); + prev_ep->next = ep->next; + micro_unlock_endpoint(prev_ep); } }