]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: make usleep_safe() return earlier if 0 is passed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 19 Dec 2023 15:48:49 +0000 (00:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 19 Dec 2023 18:07:46 +0000 (03:07 +0900)
src/basic/time-util.h

index ed4c1aabd489f1674cc1ac99d9cd6cf2fe645ef8..29373477f486deda53d5975a55ca3e24430e409f 100644 (file)
@@ -219,6 +219,9 @@ static inline int usleep_safe(usec_t usec) {
          * ⚠️ Note we are not using plain nanosleep() here, since that operates on CLOCK_REALTIME, not
          *    CLOCK_MONOTONIC! */
 
+        if (usec == 0)
+                return 0;
+
         // FIXME: use RET_NERRNO() macro here. Currently, this header cannot include errno-util.h.
         return clock_nanosleep(CLOCK_MONOTONIC, 0, TIMESPEC_STORE(usec), NULL) < 0 ? -errno : 0;
 }