[systemd-devel] sdbus_event loop state mark as volatile?

Stephen Hemminger stephen at networkplumber.org
Thu Sep 5 17:46:12 UTC 2019


The libsystemd bus event loop is:


        while (e->state != SD_EVENT_FINISHED) {
                r = sd_event_run(e, (uint64_t) -1);
    
But since e->state is changed by another thread it
should be marked volatile to avoid compiler thinking
the state doesn't get changed.


diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 5adbceeb0247..b7be2472a398 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -90,7 +90,7 @@ struct sd_event {
 
         uint64_t iteration;
         triple_timestamp timestamp;
-        int state;
+        volatile int state;
 
         bool exit_requested:1;
         bool need_process_child:1;


More information about the systemd-devel mailing list