This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/scheduled_event_on_event_thread
in repository https://gitbox.apache.org/repos/asf/celix.git

commit e42ee60edbccfbc7df31ee333a174335328d432a
Author: Pepijn Noltes <[email protected]>
AuthorDate: Thu Jun 15 20:00:37 2023 +0200

    Make callbacks in ScheduledEvent static
---
 libs/framework/include/celix/ScheduledEvent.h | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/libs/framework/include/celix/ScheduledEvent.h 
b/libs/framework/include/celix/ScheduledEvent.h
index 9b9e2b1b..06c52684 100644
--- a/libs/framework/include/celix/ScheduledEvent.h
+++ b/libs/framework/include/celix/ScheduledEvent.h
@@ -102,6 +102,8 @@ class ScheduledEvent final {
         std::function<void()> removeCallback{};        /**< The remove 
callback for the scheduled event. */
     };
 
+    static void (*callback)(void*);
+
     /**
      * @brief Constructs a scheduled event using the given bundle context and 
options.
      *
@@ -113,24 +115,25 @@ class ScheduledEvent final {
                    std::function<void()> _callback,
                    std::function<void()> _removeCallback,
                    celix_scheduled_event_options_t& options) {
-        ctx = std::move(_cCtx);
-        isOneShot = options.intervalInSeconds == 0;
-        options.name = _name.c_str();
-        auto* callbacks = new Callbacks{std::move(_callback), 
std::move(_removeCallback)};
-        options.callbackData = callbacks;
-        options.callback = [](void* data) {
+        static auto callback = [](void* data) {
             auto* callbacks = static_cast<Callbacks*>(data);
             (callbacks->callback)();
         };
-        options.removeCallbackData = callbacks;
-        options.removeCallback = [](void* data) {
+        static auto removeCallback = [](void* data) {
             auto* callbacks = static_cast<Callbacks*>(data);
             if (callbacks->removeCallback) {
                 (callbacks->removeCallback)();
             }
-            delete callbacks;
         };
 
+        ctx = std::move(_cCtx);
+        isOneShot = options.intervalInSeconds == 0;
+        options.name = _name.c_str();
+        auto* callbacks = new Callbacks{std::move(_callback), 
std::move(_removeCallback)};
+        options.callbackData = callbacks;
+        options.callback = callback;
+        options.removeCallbackData = callbacks;
+        options.removeCallback = removeCallback;
         eventId = celix_bundleContext_scheduleEvent(ctx.get(), &options);
     }
 

Reply via email to