<div dir="ltr">You are free to relicense to BSD-2 if it looks clean.<div><br></div><div>Why doesn't per item compilation and linking avoid this dependency?</div><div><br></div><div>It looks OK otherwise.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 17, 2021 at 10:01 AM Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Move clock_nanosleep() to a separate file to avoid a dependency on errno<br>
which pulls in the Newlib reentrancy support.<br>
---<br>
cpukit/Makefile.am | 1 +<br>
cpukit/posix/src/clocknanosleep.c | 116 ++++++++++++++++++++++++++++++<br>
cpukit/posix/src/nanosleep.c | 91 -----------------------<br>
spec/build/cpukit/librtemscpu.yml | 1 +<br>
4 files changed, 118 insertions(+), 91 deletions(-)<br>
create mode 100644 cpukit/posix/src/clocknanosleep.c<br>
<br>
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am<br>
index 0178d5d82a..a5f3a9665f 100644<br>
--- a/cpukit/Makefile.am<br>
+++ b/cpukit/Makefile.am<br>
@@ -490,6 +490,7 @@ librtemscpu_a_SOURCES += posix/src/cleanuppush.c<br>
librtemscpu_a_SOURCES += posix/src/clockgetcpuclockid.c<br>
librtemscpu_a_SOURCES += posix/src/clockgetres.c<br>
librtemscpu_a_SOURCES += posix/src/clockgettime.c<br>
+librtemscpu_a_SOURCES += posix/src/clocknanosleep.c<br>
librtemscpu_a_SOURCES += posix/src/clocksettime.c<br>
librtemscpu_a_SOURCES += posix/src/condattrdestroy.c<br>
librtemscpu_a_SOURCES += posix/src/condattrgetclock.c<br>
diff --git a/cpukit/posix/src/clocknanosleep.c b/cpukit/posix/src/clocknanosleep.c<br>
new file mode 100644<br>
index 0000000000..73b7d9c6a1<br>
--- /dev/null<br>
+++ b/cpukit/posix/src/clocknanosleep.c<br>
@@ -0,0 +1,116 @@<br>
+/**<br>
+ * @file<br>
+ *<br>
+ * @ingroup POSIXAPI<br>
+ *<br>
+ * @brief Suspends Execution of calling thread until Time elapses<br>
+ */<br>
+<br>
+/*<br>
+ * COPYRIGHT (c) 1989-2015.<br>
+ * On-Line Applications Research Corporation (OAR).<br>
+ * <br>
+ * Copyright (c) 2016. Gedare Bloom.<br>
+ *<br>
+ * The license and distribution terms for this file may be<br>
+ * found in the file LICENSE in this distribution or at<br>
+ * <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/LICENSE</a>.<br>
+ */<br>
+<br>
+#ifdef HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <time.h><br>
+<br>
+#include <rtems/score/threadimpl.h><br>
+#include <rtems/score/threadqimpl.h><br>
+#include <rtems/score/timespec.h><br>
+#include <rtems/score/timecounter.h><br>
+#include <rtems/score/watchdogimpl.h><br>
+#include <rtems/posix/posixapi.h><br>
+<br>
+static Thread_queue_Control _Nanosleep_Pseudo_queue =<br>
+ THREAD_QUEUE_INITIALIZER( "Nanosleep" );<br>
+<br>
+/*<br>
+ * High Resolution Sleep with Specifiable Clock, IEEE Std 1003.1, 2001<br>
+ */<br>
+int clock_nanosleep(<br>
+ clockid_t clock_id,<br>
+ int flags,<br>
+ const struct timespec *rqtp,<br>
+ struct timespec *rmtp<br>
+)<br>
+{<br>
+ Thread_queue_Context queue_context;<br>
+ struct timespec uptime;<br>
+ const struct timespec *end;<br>
+ Thread_Control *executing;<br>
+ int eno;<br>
+<br>
+ if ( clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC ) {<br>
+ return ENOTSUP;<br>
+ }<br>
+<br>
+ _Thread_queue_Context_initialize( &queue_context );<br>
+ _Thread_queue_Context_set_thread_state(<br>
+ &queue_context,<br>
+ STATES_WAITING_FOR_TIME | STATES_INTERRUPTIBLE_BY_SIGNAL<br>
+ );<br>
+<br>
+ if ( ( flags & TIMER_ABSTIME ) != 0 ) {<br>
+ end = rqtp;<br>
+<br>
+ if ( clock_id == CLOCK_REALTIME ) {<br>
+ _Thread_queue_Context_set_enqueue_timeout_realtime_timespec(<br>
+ &queue_context,<br>
+ end<br>
+ );<br>
+ } else {<br>
+ _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(<br>
+ &queue_context,<br>
+ end<br>
+ );<br>
+ }<br>
+ } else {<br>
+ _Timecounter_Nanouptime( &uptime );<br>
+ end = _Watchdog_Future_timespec( &uptime, rqtp );<br>
+ _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(<br>
+ &queue_context,<br>
+ end<br>
+ );<br>
+ }<br>
+<br>
+ _Thread_queue_Acquire( &_Nanosleep_Pseudo_queue, &queue_context );<br>
+ executing = _Thread_Executing;<br>
+ _Thread_queue_Enqueue(<br>
+ &_Nanosleep_Pseudo_queue.Queue,<br>
+ &_Thread_queue_Operations_FIFO,<br>
+ executing,<br>
+ &queue_context<br>
+ );<br>
+ eno = _POSIX_Get_error_after_wait( executing );<br>
+<br>
+ if ( eno == ETIMEDOUT ) {<br>
+ eno = 0;<br>
+ }<br>
+<br>
+ if ( rmtp != NULL && ( flags & TIMER_ABSTIME ) == 0 ) {<br>
+ if ( eno == EINTR ) {<br>
+ struct timespec actual_end;<br>
+<br>
+ _Timecounter_Nanouptime( &actual_end );<br>
+<br>
+ if ( _Timespec_Less_than( &actual_end, end ) ) {<br>
+ _Timespec_Subtract( &actual_end, end, rmtp );<br>
+ } else {<br>
+ _Timespec_Set_to_zero( rmtp );<br>
+ }<br>
+ } else {<br>
+ _Timespec_Set_to_zero( rmtp );<br>
+ }<br>
+ }<br>
+<br>
+ return eno;<br>
+}<br>
diff --git a/cpukit/posix/src/nanosleep.c b/cpukit/posix/src/nanosleep.c<br>
index 8d1a4b84e4..167dcbc787 100644<br>
--- a/cpukit/posix/src/nanosleep.c<br>
+++ b/cpukit/posix/src/nanosleep.c<br>
@@ -23,17 +23,8 @@<br>
<br>
#include <time.h><br>
<br>
-#include <rtems/score/threadimpl.h><br>
-#include <rtems/score/threadqimpl.h><br>
-#include <rtems/score/timespec.h><br>
-#include <rtems/score/timecounter.h><br>
-#include <rtems/score/watchdogimpl.h><br>
-#include <rtems/posix/posixapi.h><br>
#include <rtems/seterr.h><br>
<br>
-static Thread_queue_Control _Nanosleep_Pseudo_queue =<br>
- THREAD_QUEUE_INITIALIZER( "Nanosleep" );<br>
-<br>
/*<br>
* 14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269<br>
*/<br>
@@ -52,85 +43,3 @@ int nanosleep(<br>
<br>
return eno;<br>
}<br>
-<br>
-/*<br>
- * High Resolution Sleep with Specifiable Clock, IEEE Std 1003.1, 2001<br>
- */<br>
-int clock_nanosleep(<br>
- clockid_t clock_id,<br>
- int flags,<br>
- const struct timespec *rqtp,<br>
- struct timespec *rmtp<br>
-)<br>
-{<br>
- Thread_queue_Context queue_context;<br>
- struct timespec uptime;<br>
- const struct timespec *end;<br>
- Thread_Control *executing;<br>
- int eno;<br>
-<br>
- if ( clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC ) {<br>
- return ENOTSUP;<br>
- }<br>
-<br>
- _Thread_queue_Context_initialize( &queue_context );<br>
- _Thread_queue_Context_set_thread_state(<br>
- &queue_context,<br>
- STATES_WAITING_FOR_TIME | STATES_INTERRUPTIBLE_BY_SIGNAL<br>
- );<br>
-<br>
- if ( ( flags & TIMER_ABSTIME ) != 0 ) {<br>
- end = rqtp;<br>
-<br>
- if ( clock_id == CLOCK_REALTIME ) {<br>
- _Thread_queue_Context_set_enqueue_timeout_realtime_timespec(<br>
- &queue_context,<br>
- end<br>
- );<br>
- } else {<br>
- _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(<br>
- &queue_context,<br>
- end<br>
- );<br>
- }<br>
- } else {<br>
- _Timecounter_Nanouptime( &uptime );<br>
- end = _Watchdog_Future_timespec( &uptime, rqtp );<br>
- _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(<br>
- &queue_context,<br>
- end<br>
- );<br>
- }<br>
-<br>
- _Thread_queue_Acquire( &_Nanosleep_Pseudo_queue, &queue_context );<br>
- executing = _Thread_Executing;<br>
- _Thread_queue_Enqueue(<br>
- &_Nanosleep_Pseudo_queue.Queue,<br>
- &_Thread_queue_Operations_FIFO,<br>
- executing,<br>
- &queue_context<br>
- );<br>
- eno = _POSIX_Get_error_after_wait( executing );<br>
-<br>
- if ( eno == ETIMEDOUT ) {<br>
- eno = 0;<br>
- }<br>
-<br>
- if ( rmtp != NULL && ( flags & TIMER_ABSTIME ) == 0 ) {<br>
- if ( eno == EINTR ) {<br>
- struct timespec actual_end;<br>
-<br>
- _Timecounter_Nanouptime( &actual_end );<br>
-<br>
- if ( _Timespec_Less_than( &actual_end, end ) ) {<br>
- _Timespec_Subtract( &actual_end, end, rmtp );<br>
- } else {<br>
- _Timespec_Set_to_zero( rmtp );<br>
- }<br>
- } else {<br>
- _Timespec_Set_to_zero( rmtp );<br>
- }<br>
- }<br>
-<br>
- return eno;<br>
-}<br>
diff --git a/spec/build/cpukit/librtemscpu.yml b/spec/build/cpukit/librtemscpu.yml<br>
index 682032182f..efd0d1bfe1 100644<br>
--- a/spec/build/cpukit/librtemscpu.yml<br>
+++ b/spec/build/cpukit/librtemscpu.yml<br>
@@ -990,6 +990,7 @@ source:<br>
- cpukit/posix/src/clockgetcpuclockid.c<br>
- cpukit/posix/src/clockgetres.c<br>
- cpukit/posix/src/clockgettime.c<br>
+- cpukit/posix/src/clocknanosleep.c<br>
- cpukit/posix/src/clocksettime.c<br>
- cpukit/posix/src/condattrdestroy.c<br>
- cpukit/posix/src/condattrgetclock.c<br>
-- <br>
2.26.2<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>