]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-event: expose the event loop iteration counter via sd_event_get_iteration() (...
authorLennart Poettering <lennart@poettering.net>
Thu, 30 Jun 2016 19:25:07 +0000 (12:25 -0700)
committerMartin Pitt <martin.pitt@ubuntu.com>
Thu, 30 Jun 2016 19:25:07 +0000 (21:25 +0200)
This extends the existing event loop iteration counter to 64bit, and exposes it
via a new function sd_event_get_iteration(). This is helpful for cases like
issue #3612. After all, since we maintain the counter anyway, we might as well
expose it.

(This also fixes an unrelated issue in the man page for sd_event_wait() where
micro and milliseconds got mixed up)

Makefile-man.am
man/sd_event_wait.xml
src/libsystemd/libsystemd.sym
src/libsystemd/sd-event/sd-event.c
src/systemd/sd-event.h

index cd7583bed7fdd9827f9d45db44099202e5c1feac..8ab733360dd46e3cbbb6939c321474b31598409e 100644 (file)
@@ -338,6 +338,7 @@ MANPAGES_ALIAS += \
        man/sd_event_default.3 \
        man/sd_event_dispatch.3 \
        man/sd_event_get_exit_code.3 \
+       man/sd_event_get_iteration.3 \
        man/sd_event_get_state.3 \
        man/sd_event_get_tid.3 \
        man/sd_event_get_watchdog.3 \
@@ -669,6 +670,7 @@ man/sd_event_child_handler_t.3: man/sd_event_add_child.3
 man/sd_event_default.3: man/sd_event_new.3
 man/sd_event_dispatch.3: man/sd_event_wait.3
 man/sd_event_get_exit_code.3: man/sd_event_exit.3
+man/sd_event_get_iteration.3: man/sd_event_wait.3
 man/sd_event_get_state.3: man/sd_event_wait.3
 man/sd_event_get_tid.3: man/sd_event_new.3
 man/sd_event_get_watchdog.3: man/sd_event_set_watchdog.3
@@ -1318,6 +1320,9 @@ man/sd_event_dispatch.html: man/sd_event_wait.html
 man/sd_event_get_exit_code.html: man/sd_event_exit.html
        $(html-alias)
 
+man/sd_event_get_iteration.html: man/sd_event_wait.html
+       $(html-alias)
+
 man/sd_event_get_state.html: man/sd_event_wait.html
        $(html-alias)
 
index f2aea00e985c0dc05cf358445111918f0d922c85..26327dc6881ad8cda650b00e5f8357b1917f4b5c 100644 (file)
@@ -47,6 +47,7 @@
     <refname>sd_event_prepare</refname>
     <refname>sd_event_dispatch</refname>
     <refname>sd_event_get_state</refname>
+    <refname>sd_event_get_iteration</refname>
     <refname>SD_EVENT_INITIAL</refname>
     <refname>SD_EVENT_PREPARING</refname>
     <refname>SD_EVENT_ARMED</refname>
         <paramdef>sd_event *<parameter>event</parameter></paramdef>
       </funcprototype>
 
+      <funcprototype>
+        <funcdef>int <function>sd_event_get_iteration</function></funcdef>
+        <paramdef>sd_event *<parameter>event</parameter></paramdef>
+        <paramdef>uint64_t *<parameter>ret</parameter></paramdef>
+      </funcprototype>
+
     </funcsynopsis>
   </refsynopsisdiv>
 
     determine the state the event loop is currently in. It returns one
     of the states described below.</para>
 
-    <para>All four functions take, as the first argument, the event
-    loop object <parameter>event</parameter> that has been created
-    with <function>sd_event_new()</function>. The timeout for
-    <function>sd_event_wait()</function> is specified in
-    <parameter>usec</parameter> in milliseconds.  <constant>(uint64_t)
-    -1</constant> may be used to specify an infinite timeout.</para>
+    <para><function>sd_event_get_iteration()</function> may be used to determine the current iteration of the event
+    loop. It returns an unsigned 64bit integer containing a counter that increases monotonically with each iteration of
+    the event loop, starting with 0. The counter is increased at the time of the
+    <function>sd_event_prepare()</function> invocation.</para>
+
+    <para>All five functions take, as the first argument, the event loop object <parameter>event</parameter> that has
+    been created with <function>sd_event_new()</function>. The timeout for <function>sd_event_wait()</function> is
+    specified in <parameter>usec</parameter> in microseconds.  <constant>(uint64_t) -1</constant> may be used to
+    specify an infinite timeout.</para>
 </refsect1>
 
   <refsect1>
index 0b3a1708dc69a461e9d73617b4a6976fe2f18054..542254295cf0c8c4cde134c30c6e5ba7b4916f49 100644 (file)
@@ -495,3 +495,8 @@ global:
         sd_journal_open_directory_fd;
         sd_journal_open_files_fd;
 } LIBSYSTEMD_229;
+
+LIBSYSTEMD_231 {
+global:
+        sd_event_get_iteration;
+} LIBSYSTEMD_230;
index f364b54b50645de3783a18bbb7457103a459d2ad..9857f8b1fc31930e62d614c2af03023056660025 100644 (file)
@@ -109,8 +109,8 @@ struct sd_event_source {
         int64_t priority;
         unsigned pending_index;
         unsigned prepare_index;
-        unsigned pending_iteration;
-        unsigned prepare_iteration;
+        uint64_t pending_iteration;
+        uint64_t prepare_iteration;
 
         LIST_FIELDS(sd_event_source, sources);
 
@@ -215,7 +215,7 @@ struct sd_event {
 
         pid_t original_pid;
 
-        unsigned iteration;
+        uint64_t iteration;
         triple_timestamp timestamp;
         int state;
 
@@ -2874,3 +2874,11 @@ _public_ int sd_event_get_watchdog(sd_event *e) {
 
         return e->watchdog;
 }
+
+_public_ int sd_event_get_iteration(sd_event *e, uint64_t *ret) {
+        assert_return(e, -EINVAL);
+        assert_return(!event_pid_changed(e), -ECHILD);
+
+        *ret = e->iteration;
+        return 0;
+}
index 531ace1c34eb60bc19c29af10b3b649d5e995773..cc26b7df553b2499b33bb5530e52477d33025b24 100644 (file)
@@ -104,6 +104,7 @@ int sd_event_get_tid(sd_event *e, pid_t *tid);
 int sd_event_get_exit_code(sd_event *e, int *code);
 int sd_event_set_watchdog(sd_event *e, int b);
 int sd_event_get_watchdog(sd_event *e);
+int sd_event_get_iteration(sd_event *e, uint64_t *ret);
 
 sd_event_source* sd_event_source_ref(sd_event_source *s);
 sd_event_source* sd_event_source_unref(sd_event_source *s);