[PATCH v2 07/20] lib/cobalt: cond: Move all time64 related services to wrappers_time64.c

Florian Bezdeka <[email protected]>
Newsgroups dev.linux.lists.xenomai
Message-ID <20260302-wip-flo-fix-time64-32bit-native-v2-7-7caefce29bcd@siemens.com>
Code movement with some minor adjustments to the doxygen headers.
All services should remain in the cobalt_api_cond group.

Signed-off-by: Florian Bezdeka <[email protected]>
---
 lib/cobalt/cond.c            | 87 ------------------------------------------
 lib/cobalt/wrappers_time64.c | 90 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 87 deletions(-)

diff --git a/lib/cobalt/cond.c b/lib/cobalt/cond.c
index 7be7fca01f53930f8504945206b2ee6ba6be1ba5..fb700f4500a6f1e7a0331954f7a5f5a8a3bf1052 100644
--- a/lib/cobalt/cond.c
+++ b/lib/cobalt/cond.c
@@ -282,93 +282,6 @@ COBALT_IMPL(int, pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mute
 	return -err ?: -c.err;
 }
 
-/**
- * Wait a bounded time on a condition variable.
- *
- * This service is equivalent to pthread_cond_wait(), except that the calling
- * thread remains blocked on the condition variable @a cnd only until the
- * timeout specified by @a abstime expires.
- *
- * The timeout @a abstime is expressed as an absolute value of the @a clock
- * attribute passed to pthread_cond_init(). By default, @a CLOCK_REALTIME is
- * used.
- *
- * @param cond the condition variable to wait for;
- *
- * @param mutex the mutex associated with @a cnd;
- *
- * @param abstime the timeout, expressed as an absolute value of the clock
- * attribute passed to pthread_cond_init().
- *
- * @return 0 on success,
- * @return an error number if:
- * - EPERM, the caller context is invalid;
- * - EPERM, the specified condition variable is not process-shared and does not
- *   belong to the current process;
- * - EINVAL, the specified condition variable, mutex or timeout is invalid;
- * - EINVAL, another thread is currently blocked on @a cnd using another mutex
- *   than @a mx;
- * - EPERM, the specified mutex is not owned by the caller;
- * - ETIMEDOUT, the specified timeout expired.
- *
- * @see
- * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_cond_timedwait.html">
- * Specification.</a>
- *
- * @apitags{xthread-only, switch-primary}
- */
-COBALT_IMPL_TIME64(int, pthread_cond_timedwait, __pthread_cond_timedwait64,
-		   (pthread_cond_t *cond, pthread_mutex_t *mutex,
-		    const struct timespec *abstime))
-{
-	struct cobalt_cond_shadow *_cnd = &((union cobalt_cond_union *)cond)->shadow_cond;
-	struct cobalt_mutex_shadow *_mx =
-		&((union cobalt_mutex_union *)mutex)->shadow_mutex;
-	struct cobalt_cond_cleanup_t c = {
-		.cond = _cnd,
-		.mutex = _mx,
-	};
-	int err, oldtype;
-
-	if (_mx->magic != COBALT_MUTEX_MAGIC)
-		return EINVAL;
-
-	err = cobalt_cond_autoinit((union cobalt_cond_union *)cond);
-	if (err)
-		return err;
-
-	if (_mx->attr.type == PTHREAD_MUTEX_ERRORCHECK) {
-		xnhandle_t cur = cobalt_get_current();
-
-		if (cur == XN_NO_HANDLE)
-			return EPERM;
-
-		if (xnsynch_fast_owner_check(mutex_get_ownerp(_mx), cur))
-			return EPERM;
-	}
-
-	c.count = _mx->lockcnt;
-
-	pthread_cleanup_push(&__pthread_cond_cleanup, &c);
-
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
-
-	err = do_sc_cond_wait_prologue(_cnd, _mx, &c.err, 1, abstime);
-
-	pthread_setcanceltype(oldtype, NULL);
-
-	pthread_cleanup_pop(0);
-
-	while (err == -EINTR) {
-		err = XENOMAI_SYSCALL2(sc_cobalt_cond_wait_epilogue, _cnd, _mx);
-		pthread_testcancel();
-	}
-
-	_mx->lockcnt = c.count;
-
-	return -err ?: -c.err;
-}
-
 /**
  * Signal a condition variable.
  *
diff --git a/lib/cobalt/wrappers_time64.c b/lib/cobalt/wrappers_time64.c
index a42302d674388fd7de5930ef9d99c6b9f0597279..ef2fb9869976fa9a60f45dab0a6ded1606ebf21d 100644
--- a/lib/cobalt/wrappers_time64.c
+++ b/lib/cobalt/wrappers_time64.c
@@ -12,6 +12,7 @@
  * time_t.
  */
 
+#include "cond.h"
 #include "internal.h"
 
 #include <asm/xenomai/syscall.h>
@@ -338,3 +339,92 @@ COBALT_IMPL_TIME64(time_t, time, __time64, (time_t *t))
 		*t = ts.tv_sec;
 	return ts.tv_sec;
 }
+
+/**
+ * Wait a bounded time on a condition variable.
+ * @ingroup cobalt_api_cond
+ *
+ * This service is equivalent to pthread_cond_wait(), except that the calling
+ * thread remains blocked on the condition variable @a cnd only until the
+ * timeout specified by @a abstime expires.
+ *
+ * The timeout @a abstime is expressed as an absolute value of the @a clock
+ * attribute passed to pthread_cond_init(). By default, @a CLOCK_REALTIME is
+ * used.
+ *
+ * @param cond the condition variable to wait for;
+ *
+ * @param mutex the mutex associated with @a cnd;
+ *
+ * @param abstime the timeout, expressed as an absolute value of the clock
+ * attribute passed to pthread_cond_init().
+ *
+ * @return 0 on success,
+ * @return an error number if:
+ * - EPERM, the caller context is invalid;
+ * - EPERM, the specified condition variable is not process-shared and does not
+ *   belong to the current process;
+ * - EINVAL, the specified condition variable, mutex or timeout is invalid;
+ * - EINVAL, another thread is currently blocked on @a cnd using another mutex
+ *   than @a mx;
+ * - EPERM, the specified mutex is not owned by the caller;
+ * - ETIMEDOUT, the specified timeout expired.
+ *
+ * @see
+ * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_cond_timedwait.html">
+ * Specification.</a>
+ *
+ * @apitags{xthread-only, switch-primary}
+ */
+COBALT_IMPL_TIME64(int, pthread_cond_timedwait, __pthread_cond_timedwait64,
+		   (pthread_cond_t *cond, pthread_mutex_t *mutex,
+		    const struct timespec *abstime))
+{
+	struct cobalt_cond_shadow *_cnd =
+		&((union cobalt_cond_union *)cond)->shadow_cond;
+	struct cobalt_mutex_shadow *_mx =
+		&((union cobalt_mutex_union *)mutex)->shadow_mutex;
+	struct cobalt_cond_cleanup_t c = {
+		.cond = _cnd,
+		.mutex = _mx,
+	};
+	int err, oldtype;
+
+	if (_mx->magic != COBALT_MUTEX_MAGIC)
+		return EINVAL;
+
+	err = cobalt_cond_autoinit((union cobalt_cond_union *)cond);
+	if (err)
+		return err;
+
+	if (_mx->attr.type == PTHREAD_MUTEX_ERRORCHECK) {
+		xnhandle_t cur = cobalt_get_current();
+
+		if (cur == XN_NO_HANDLE)
+			return EPERM;
+
+		if (xnsynch_fast_owner_check(mutex_get_ownerp(_mx), cur))
+			return EPERM;
+	}
+
+	c.count = _mx->lockcnt;
+
+	pthread_cleanup_push(&__pthread_cond_cleanup, &c);
+
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
+	err = do_sc_cond_wait_prologue(_cnd, _mx, &c.err, 1, abstime);
+
+	pthread_setcanceltype(oldtype, NULL);
+
+	pthread_cleanup_pop(0);
+
+	while (err == -EINTR) {
+		err = XENOMAI_SYSCALL2(sc_cobalt_cond_wait_epilogue, _cnd, _mx);
+		pthread_testcancel();
+	}
+
+	_mx->lockcnt = c.count;
+
+	return -err ?: -c.err;
+}

-- 
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.