Browse Source

rt: convert mq_timedsend/mq_timedreceive to use cancel.h macros

Waldemar Brodkorb 6 years ago
parent
commit
ccc200d454
8 changed files with 41 additions and 107 deletions
  1. 0 4
      include/cancel.h
  2. 1 8
      librt/Makefile.in
  3. 4 41
      librt/mq_receive.c
  4. 4 38
      librt/mq_send.c
  5. 0 8
      librt/mq_timedreceive.S
  6. 16 0
      librt/mq_timedreceive.c
  7. 0 8
      librt/mq_timedsend.S
  8. 16 0
      librt/mq_timedsend.c

+ 0 - 4
include/cancel.h

@@ -36,8 +36,6 @@
 
 #include <features.h>
 
-#ifndef NOT_IN_libc
-
 #define __NC(name) _NC(name)
 #define _NC(name) __##name##_nocancel
 
@@ -97,6 +95,4 @@ strong_alias(__NC(name),name)
 # undef LIBC_CANCEL_HANDLED
 # define LIBC_CANCEL_HANDLED()
 
-#endif /* NOT_IN_libc */
-
 #endif

+ 1 - 8
librt/Makefile.in

@@ -17,11 +17,8 @@ librt_filter_SRC :=
 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
 librt_filter_SRC += mq_notify.c timer_create.c timer_delete.c \
 	timer_getoverr.c timer_gettime.c timer_settime.c
-# these should really be guarded by ADVANCED_REALTIME, we use them in mq_send.c/mq_receive.c
-librt_SSRC := $(wildcard $(librt_DIR)/*.S)
 else
 librt_filter_SRC += clock_nanosleep.c clock_getcpuclockid.c clock_gettime.c
-librt_SSRC :=
 endif
 
 librt_filter_SRC += $(if $(UCLIBC_HAS_ADVANCED_REALTIME),, \
@@ -36,17 +33,13 @@ librt_filter_SRC += $(if $(HAS_NO_THREADS),dso_handle.c)
 
 librt_SRC := $(filter-out $(librt_filter_SRC),$(librt_SRC))
 librt_OBJ := $(patsubst %.c,$(librt_OUT)/%.o,$(librt_SRC))
-librt_OBJ += $(patsubst $(librt_DIR)/%.S,$(librt_OUT)/%.o,$(librt_SSRC))
-
-ASFLAGS-mq_timedreceive.S = -D_LIBC_REENTRANT
-ASFLAGS-mq_timedsend.S = -D_LIBC_REENTRANT
 
 ifeq ($(DOPIC),y)
 librt-a-y += $(librt_OBJ:.o=.os)
 else
 librt-a-y += $(librt_OBJ)
 endif
-librt-so-y += $(librt_OBJ:.o=.oS)
+librt-so-y += $(librt_OBJ:.o=.os)
 
 librt-dep-y := $(libc.depend)
 

+ 4 - 41
librt/mq_receive.c

@@ -2,52 +2,15 @@
  * mq_receive.c - functions for receiving from message queue.
  */
 
+#include <errno.h>
+#include <stddef.h>
 #include <sys/syscall.h>
 
-#ifdef __NR_mq_timedreceive
-
-#include <stddef.h>
 #include <mqueue.h>
 
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-# ifndef __UCLIBC_HAS_ADVANCED_REALTIME__
-extern ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
-			       unsigned int *msg_prio,
-			       const struct timespec *abs_timeout);
-# endif
-librt_hidden_proto(mq_timedreceive)
-#else
-
-# define __NR___syscall_mq_timedreceive __NR_mq_timedreceive
-static _syscall5(int, __syscall_mq_timedreceive, int, mqdes,
-		 char *, msg_ptr, size_t, msg_len, unsigned int *,
-		 msg_prio, const void *, abs_timeout)
-
-# ifdef __UCLIBC_HAS_ADVANCED_REALTIME__
-/*
- * Receive the oldest from highest priority messages.
- * Stop waiting if abs_timeout expires.
- */
-ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
-			unsigned int *msg_prio,
-			const struct timespec *abs_timeout)
-{
-	return __syscall_mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio,
-					 abs_timeout);
-}
-# endif
-
-#endif
-
-/* Receive the oldest from highest priority messages */
-ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
-		   unsigned int *msg_prio)
+#ifdef __NR_mq_timedreceive
+ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio)
 {
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
 	return mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, NULL);
-#else
-	return __syscall_mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, NULL);
-#endif
 }
-
 #endif

+ 4 - 38
librt/mq_send.c

@@ -2,49 +2,15 @@
  * mq_send.c - functions for sending to message queue.
  */
 
+#include <errno.h>
+#include <stddef.h>
 #include <sys/syscall.h>
 
-#ifdef __NR_mq_timedsend
-
-#include <stddef.h>
 #include <mqueue.h>
 
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-# ifndef __UCLIBC_HAS_ADVANCED_REALTIME__
-extern int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
-			unsigned int msg_prio, const struct timespec *abs_timeout);
-# endif
-librt_hidden_proto(mq_timedsend)
-#else
-
-# define __NR___syscall_mq_timedsend __NR_mq_timedsend
-static _syscall5(int, __syscall_mq_timedsend, int, mqdes,
-		 const char *, msg_ptr, size_t, msg_len, unsigned int,
-		 msg_prio, const void *, abs_timeout)
-
-# ifdef __UCLIBC_HAS_ADVANCED_REALTIME__
-/*
- * Add a message to queue. If O_NONBLOCK is set and queue is full, wait
- * for sufficient room in the queue until abs_timeout expires.
- */
-int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
-		 unsigned int msg_prio, const struct timespec *abs_timeout)
-{
-	return __syscall_mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio,
-				      abs_timeout);
-}
-# endif
-#endif
-
-/* Add a message to queue */
-int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
-	    unsigned int msg_prio)
+#ifdef __NR_mq_timedsend
+int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio)
 {
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
 	return mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, NULL);
-#else
-	return __syscall_mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, NULL);
-#endif
 }
-
 #endif

+ 0 - 8
librt/mq_timedreceive.S

@@ -1,8 +0,0 @@
-#include <sysdep-cancel.h>
-#ifndef __NR_mq_timedreceive
-#error Missing definition of NR_timedreceive needed for cancellation.
-#endif
-PSEUDO(mq_timedreceive, mq_timedreceive, 5)
-ret_ERRVAL
-PSEUDO_END(mq_timedreceive)
-librt_hidden_def(mq_timedreceive)

+ 16 - 0
librt/mq_timedreceive.c

@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2017 Waldemar Brodkorb <wbx@uclibc-ng.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <sys/syscall.h>
+#include <mqueue.h>
+#include <unistd.h>
+#include <cancel.h>
+
+#define __NR___mq_timedreceive_nocancel __NR_mq_timedreceive
+_syscall5(ssize_t, __NC(mq_timedreceive), mqd_t, mqdes, char *__restrict, msg_ptr, size_t, msg_len, unsigned int *__restrict, msq_prio, const struct timespec *__restrict, abs_timeout)
+
+CANCELLABLE_SYSCALL(ssize_t, mq_timedreceive, (mqd_t mqdes, char *__restrict msg_ptr, size_t msq_len, unsigned int *__restrict msq_prio, const struct timespec *__restrict abs_timeout),
+		    (mqdes, msg_ptr, msq_len, msq_prio, abs_timeout))
+lt_libc_hidden(mq_timedreceive)

+ 0 - 8
librt/mq_timedsend.S

@@ -1,8 +0,0 @@
-#include <sysdep-cancel.h>
-#ifndef __NR_mq_timedsend
-#error Missing definition of NR_timedsend needed for cancellation.
-#endif
-PSEUDO(mq_timedsend, mq_timedsend, 5)
-ret_ERRVAL
-PSEUDO_END(mq_timedsend)
-librt_hidden_def(mq_timedsend)

+ 16 - 0
librt/mq_timedsend.c

@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2017 Waldemar Brodkorb <wbx@uclibc-ng.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <sys/syscall.h>
+#include <mqueue.h>
+#include <unistd.h>
+#include <cancel.h>
+
+#define __NR___mq_timedsend_nocancel __NR_mq_timedsend
+_syscall5(int, __NC(mq_timedsend), mqd_t, mqdes, const char *, msg_ptr, size_t, msg_len, unsigned int, msq_prio, const struct timespec *, abs_timeout)
+
+CANCELLABLE_SYSCALL(int, mq_timedsend, (mqd_t mqdes, const char *msg_ptr, size_t msq_len, unsigned int msq_prio, const struct timespec *abs_timeout),
+		    (mqdes, msg_ptr, msq_len, msq_prio, abs_timeout))
+lt_libc_hidden(mq_timedsend)