pnoltes commented on code in PR #583: URL: https://github.com/apache/celix/pull/583#discussion_r1258635660
########## libs/framework/src/framework.c: ########## @@ -1408,32 +1412,151 @@ static inline bool fw_removeTopEventFromQueue(celix_framework_t* fw) { static inline void fw_handleEvents(celix_framework_t* framework) { celixThreadMutex_lock(&framework->dispatcher.mutex); int size = framework->dispatcher.eventQueueSize + celix_arrayList_size(framework->dispatcher.dynamicEventQueue); - if (size == 0 && framework->dispatcher.active) { - celixThreadCondition_timedwaitRelative(&framework->dispatcher.cond, &framework->dispatcher.mutex, 1, 0); - } - size = framework->dispatcher.eventQueueSize + celix_arrayList_size(framework->dispatcher.dynamicEventQueue); celixThreadMutex_unlock(&framework->dispatcher.mutex); while (size > 0) { celix_framework_event_t* topEvent = fw_topEventFromQueue(framework); fw_handleEventRequest(framework, topEvent); - bool dynamiclyAllocatedEvent = fw_removeTopEventFromQueue(framework); + bool dynamicallyAllocatedEvent = fw_removeTopEventFromQueue(framework); if (topEvent->bndEntry != NULL) { celix_framework_bundleEntry_decreaseUseCount(topEvent->bndEntry); } free(topEvent->serviceName); - if (dynamiclyAllocatedEvent) { + if (dynamicallyAllocatedEvent) { free(topEvent); } celixThreadMutex_lock(&framework->dispatcher.mutex); size = framework->dispatcher.eventQueueSize + celix_arrayList_size(framework->dispatcher.dynamicEventQueue); - celixThreadCondition_broadcast(&framework->dispatcher.cond); celixThreadMutex_unlock(&framework->dispatcher.mutex); } } +/** + * @brief Process all scheduled events. + */ +static double celix_framework_processScheduledEvents(celix_framework_t* fw) { + struct timespec ts = celixThreadCondition_getTime(); + + double nextClosestScheduledEvent; + celix_scheduled_event_t* callEvent; + celix_scheduled_event_t* removeEvent; + do { + nextClosestScheduledEvent = -1; //negative means no event next event + callEvent = NULL; + removeEvent = NULL; + double nextEvent; + celixThreadMutex_lock(&fw->dispatcher.mutex); + CELIX_LONG_HASH_MAP_ITERATE(fw->dispatcher.scheduledEvents, entry) { Review Comment: I think it is better to keep this as-is. A single iteration would be nicer, but the current solution only pick events once (based on a fixed `scheduleTime`) and in combination with a retain processes the event without a lock. What can happen is that new scheduled event are added during the fixed `scheduleTime` loop, but on the other hand - and by design - during the fixed `scheduleTime` loop scheduled events can also be removed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org