File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,24 @@ int nxsig_nanosleep(FAR const struct timespec *rqtp,
103
103
return - EINVAL ;
104
104
}
105
105
106
+ /* If rqtp is zero, yield CPU and return
107
+ * Notice: The behavior of sleep(0) is not defined in POSIX, so there are
108
+ * different implementations:
109
+ * 1. In Linux, nanosleep(0) will call schedule() to yield CPU:
110
+ * https://elixir.bootlin.com/linux/latest/source/kernel/time/
111
+ * hrtimer.c#L2038
112
+ * 2. In BSD, nanosleep(0) will return immediately:
113
+ * https://github.com/freebsd/freebsd-src/blob/
114
+ * 475fa89800086718bd9249fd4dc3f862549f1f78/crypto/openssh/
115
+ * openbsd-compat/bsd-misc.c#L243
116
+ */
117
+
118
+ if (rqtp -> tv_sec == 0 && rqtp -> tv_nsec == 0 )
119
+ {
120
+ sched_yield ();
121
+ return OK ;
122
+ }
123
+
106
124
/* Get the start time of the wait. Interrupts are disabled to prevent
107
125
* timer interrupts while we do tick-related calculations before and
108
126
* after the wait.
You can’t perform that action at this time.
0 commit comments