[PATCH 13/20] lib/cobalt: semaphore: Move time64 related services to wrappers_time64.c

Florian Bezdeka <[email protected]>
Newsgroups dev.linux.lists.xenomai
Message-ID <20260220-wip-flo-fix-time64-32bit-native-v1-13-731c773e72cc@siemens.com>
Code movement with some minor adjustments to the doxygen headers.
All services should remain in the cobalt_api_sem group.

Signed-off-by: Florian Bezdeka <[email protected]>
---
 lib/cobalt/semaphore.c       | 67 +++-----------------------------------------
 lib/cobalt/wrappers_time64.c | 62 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 63 deletions(-)

diff --git a/lib/cobalt/semaphore.c b/lib/cobalt/semaphore.c
index 0c1a245cd40f7e2b0e0c883f317a3bbccde5187d..1fe3581df1cb30748ed780e57cd212827dd0f4c9 100644
--- a/lib/cobalt/semaphore.c
+++ b/lib/cobalt/semaphore.c
@@ -16,14 +16,16 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
+#include "internal.h"
+
+#include <asm/xenomai/syscall.h>
+
 #include <stdlib.h>		/* For malloc & free. */
 #include <stdarg.h>
 #include <errno.h>
 #include <fcntl.h>		/* For O_CREAT. */
 #include <pthread.h>		/* For pthread_setcanceltype. */
 #include <semaphore.h>
-#include <asm/xenomai/syscall.h>
-#include "internal.h"
 
 /**
  * @ingroup cobalt_api
@@ -329,67 +331,6 @@ COBALT_IMPL(int, sem_wait, (sem_t *sem))
 	return 0;
 }
 
-/**
- * @fn int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
- * @brief Attempt to decrement a semaphore with a time limit
- *
- * This service is equivalent to sem_wait(), except that the caller is only
- * blocked until the timeout @a abs_timeout expires.
- *
- * @param sem the semaphore to be decremented;
- *
- * @param abs_timeout the timeout, expressed as an absolute value of
- * the relevant clock for the semaphore, either CLOCK_MONOTONIC if
- * SEM_RAWCLOCK was mentioned via sem_init_np(), or CLOCK_REALTIME
- * otherwise.
- *
- * @retval 0 on success;
- * @retval -1 with @a errno set if:
- * - EPERM, the caller context is invalid;
- * - EINVAL, the semaphore is invalid or uninitialized;
- * - EINVAL, the specified timeout is invalid;
- * - EPERM, the semaphore @a sm is not process-shared and does not belong to the
- *   current process;
- * - EINTR, the caller was interrupted by a signal while blocked in this
- *   service;
- * - ETIMEDOUT, the semaphore could not be decremented and the
- *   specified timeout expired.
- *
- * @see
- * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/sem_timedwait.html">
- * Specification.</a>
- *
- * @apitags{xthread-only, switch-primary}
- */
-COBALT_IMPL_TIME64(int, sem_timedwait, __sem_timedwait64,
-		   (sem_t *sem, const struct timespec *abs_timeout))
-{
-	struct cobalt_sem_shadow *_sem = &((union cobalt_sem_union *)sem)->shadow_sem;
-	int ret, oldtype;
-
-	ret = __RT(sem_trywait(sem));
-	if (ret != -1 || errno != EAGAIN)
-		return ret;
-
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
-
-#ifdef __USE_TIME_BITS64
-	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait64, _sem,
-			       abs_timeout);
-#else
-	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait, _sem, abs_timeout);
-#endif
-
-	pthread_setcanceltype(oldtype, NULL);
-
-	if (ret) {
-		errno = -ret;
-		return -1;
-	}
-
-	return 0;
-}
-
 /**
  * @fn int sem_getvalue(sem_t sem, int *sval_r)
  * @brief Get the value of a semaphore.
diff --git a/lib/cobalt/wrappers_time64.c b/lib/cobalt/wrappers_time64.c
index 7b634976eb07d7ae143b4567983dbea7f4ddebea..1a4a3c463543e078e43eddd9ccd056ad10f69e97 100644
--- a/lib/cobalt/wrappers_time64.c
+++ b/lib/cobalt/wrappers_time64.c
@@ -840,3 +840,65 @@ COBALT_IMPL_TIME64(int, select, __select64,
 {
 	return do_select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
 }
+
+/**
+ * @fn int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
+ * @brief Attempt to decrement a semaphore with a time limit
+ * @ingroup cobalt_api_sem
+ *
+ * This service is equivalent to sem_wait(), except that the caller is only
+ * blocked until the timeout @a abs_timeout expires.
+ *
+ * @param sem the semaphore to be decremented;
+ *
+ * @param abs_timeout the timeout, expressed as an absolute value of
+ * the relevant clock for the semaphore, either CLOCK_MONOTONIC if
+ * SEM_RAWCLOCK was mentioned via sem_init_np(), or CLOCK_REALTIME
+ * otherwise.
+ *
+ * @retval 0 on success;
+ * @retval -1 with @a errno set if:
+ * - EPERM, the caller context is invalid;
+ * - EINVAL, the semaphore is invalid or uninitialized;
+ * - EINVAL, the specified timeout is invalid;
+ * - EPERM, the semaphore @a sm is not process-shared and does not belong to the
+ *   current process;
+ * - EINTR, the caller was interrupted by a signal while blocked in this
+ *   service;
+ * - ETIMEDOUT, the semaphore could not be decremented and the
+ *   specified timeout expired.
+ *
+ * @see
+ * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/sem_timedwait.html">
+ * Specification.</a>
+ *
+ * @apitags{xthread-only, switch-primary}
+ */
+COBALT_IMPL_TIME64(int, sem_timedwait, __sem_timedwait64,
+		   (sem_t *sem, const struct timespec *abs_timeout))
+{
+	struct cobalt_sem_shadow *_sem =
+		&((union cobalt_sem_union *)sem)->shadow_sem;
+	int ret, oldtype;
+
+	ret = __RT(sem_trywait(sem));
+	if (ret != -1 || errno != EAGAIN)
+		return ret;
+
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
+#ifdef __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait64, _sem, abs_timeout);
+#else
+	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait, _sem, abs_timeout);
+#endif
+
+	pthread_setcanceltype(oldtype, NULL);
+
+	if (ret) {
+		errno = -ret;
+		return -1;
+	}
+
+	return 0;
+}

-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.