summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2011-11-06 12:15:51 +0000
committerguenther <guenther@openbsd.org>2011-11-06 12:15:51 +0000
commit9b21e0e3ad3a7543cfbc9331f8899d98b97ffba9 (patch)
tree58da4aa91f6e16818cb68fbaaaf74b684c1f763a
parentDocument a non-obvious reason why something can't overflow. (diff)
downloadwireguard-openbsd-9b21e0e3ad3a7543cfbc9331f8899d98b97ffba9.tar.xz
wireguard-openbsd-9b21e0e3ad3a7543cfbc9331f8899d98b97ffba9.zip
Copy support for sched_get_priority_{min,max} from libpthread.
Requested by many to ease substitution of librthread for libpthread
-rw-r--r--lib/librthread/Makefile4
-rw-r--r--lib/librthread/rthread.h5
-rw-r--r--lib/librthread/sched_prio.c44
3 files changed, 50 insertions, 3 deletions
diff --git a/lib/librthread/Makefile b/lib/librthread/Makefile
index c8670e4abbe..427a8fa0d5b 100644
--- a/lib/librthread/Makefile
+++ b/lib/librthread/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.16 2011/10/17 06:39:20 guenther Exp $
+# $OpenBSD: Makefile,v 1.17 2011/11/06 12:15:51 guenther Exp $
LIB=rthread
WANTLINT=
@@ -12,7 +12,7 @@ CFLAGS+=-I${LIBCSRCDIR}/arch/${MACHINE_CPU} -I${LIBCSRCDIR}/include
.PATH: ${.CURDIR}/arch/${MACHINE_CPU}
SRCS= rthread.c rthread_attr.c rthread_sched.c rthread_sync.c rthread_tls.c \
rthread_sig.c rthread_np.c rthread_debug.c rthread_stack.c \
- rthread_libc.c rthread_fork.c rthread_file.c
+ rthread_libc.c rthread_fork.c rthread_file.c sched_prio.c
OBJS+= _atomic_lock.o rfork_thread.o cerror.o
diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h
index 739ec7fa31d..adc0b28f942 100644
--- a/lib/librthread/rthread.h
+++ b/lib/librthread/rthread.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.h,v 1.27 2011/11/06 11:48:59 guenther Exp $ */
+/* $OpenBSD: rthread.h,v 1.28 2011/11/06 12:15:51 guenther Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -95,6 +95,9 @@ struct pthread_attr {
int create_suspended;
};
+#define PTHREAD_MIN_PRIORITY 0
+#define PTHREAD_MAX_PRIORITY 31
+
struct rthread_key {
int used;
void (*destructor)(void *);
diff --git a/lib/librthread/sched_prio.c b/lib/librthread/sched_prio.c
new file mode 100644
index 00000000000..96e45142463
--- /dev/null
+++ b/lib/librthread/sched_prio.c
@@ -0,0 +1,44 @@
+/* $OpenBSD: sched_prio.c,v 1.1 2011/11/06 12:15:51 guenther Exp $ */
+
+/*
+ * Copyright (c) 2010 Federico G. Schwindt <fgsch@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for
+ * any purpose with or without fee is hereby granted, provided that
+ * the above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+ * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <pthread.h>
+#include <errno.h>
+#include "rthread.h"
+
+int
+sched_get_priority_max(int policy)
+{
+ if (policy < SCHED_FIFO || policy > SCHED_RR) {
+ errno = EINVAL;
+ return (-1);
+ }
+ return (PTHREAD_MAX_PRIORITY);
+}
+
+int
+sched_get_priority_min(int policy)
+{
+ if (policy < SCHED_FIFO || policy > SCHED_RR) {
+ errno = EINVAL;
+ return (-1);
+ }
+ return (PTHREAD_MIN_PRIORITY);
+}
+