summaryrefslogtreecommitdiffstats
path: root/lib/librthread/rthread_sched.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2005-12-31 08:51:20 +0000
committerotto <otto@openbsd.org>2005-12-31 08:51:20 +0000
commit8af1ee89e9eb2a63153d29bf7c43181f17d3011a (patch)
tree55ce050f62ff50db5c63ae432faf70f3c7f935ce /lib/librthread/rthread_sched.c
parentAdd AMD-8111 SMBus controller driver. (diff)
downloadwireguard-openbsd-8af1ee89e9eb2a63153d29bf7c43181f17d3011a.tar.xz
wireguard-openbsd-8af1ee89e9eb2a63153d29bf7c43181f17d3011a.zip
Implement suspend/resume and creation of initially suspended threads.
With this, java seems to be operational. Also make threads_ready non-static, which is needed for an upcoming diff. ok tedu@
Diffstat (limited to 'lib/librthread/rthread_sched.c')
-rw-r--r--lib/librthread/rthread_sched.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/lib/librthread/rthread_sched.c b/lib/librthread/rthread_sched.c
index d1dae0867b6..a1919c467d8 100644
--- a/lib/librthread/rthread_sched.c
+++ b/lib/librthread/rthread_sched.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sched.c,v 1.4 2005/12/30 04:05:55 tedu Exp $ */
+/* $OpenBSD: rthread_sched.c,v 1.5 2005/12/31 08:51:20 otto Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -33,6 +33,7 @@
#include <errno.h>
#include <pthread.h>
+#include <pthread_np.h>
#include "rthread.h"
@@ -125,3 +126,58 @@ pthread_yield(void)
{
sched_yield();
}
+
+int
+pthread_suspend_np(pthread_t thread)
+{
+ int errn = 0;
+
+ if (thread->tid == pthread_self()->tid)
+ return (EDEADLK);
+ /*
+ * XXX Avoid a bug in current signal handling by refusing to
+ * suspend the main thread.
+ */
+ if (pthread_main_np() == 0)
+ if (kill(thread->tid, SIGSTOP) == -1)
+ errn = errno;
+ return (errn);
+}
+
+void
+pthread_suspend_all_np(void)
+{
+ pthread_t t;
+ pid_t me = getthrid();
+
+ _spinlock(&_thread_lock);
+ LIST_FOREACH(t, &_thread_list, threads)
+ if (t->tid != me)
+ pthread_suspend_np(t);
+ _spinunlock(&_thread_lock);
+}
+
+int
+pthread_resume_np(pthread_t thread)
+{
+ int errn = 0;
+
+ /* XXX check if really suspended? */
+ if (kill(thread->tid, SIGCONT) == -1)
+ errn = errno;
+ return (errn);
+}
+
+void
+pthread_resume_all_np(void)
+{
+ pthread_t t;
+ pid_t me = getthrid();
+
+ _spinlock(&_thread_lock);
+ LIST_FOREACH(t, &_thread_list, threads)
+ if (t->tid != me)
+ pthread_resume_np(t);
+ _spinunlock(&_thread_lock);
+}
+