summaryrefslogtreecommitdiff
path: root/src/thread
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-17 16:53:54 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-17 16:53:54 -0400
commit9080cc153cc2b09881c3245becbd68534db18d7c (patch)
treeddbc5aef325120e000b8e7d852f26322791deb55 /src/thread
parenteb0e8fa0b1960cff4bd65ebefc798f70273b0bc9 (diff)
downloadmusl-9080cc153cc2b09881c3245becbd68534db18d7c.tar.gz
musl-9080cc153cc2b09881c3245becbd68534db18d7c.tar.bz2
musl-9080cc153cc2b09881c3245becbd68534db18d7c.tar.xz
musl-9080cc153cc2b09881c3245becbd68534db18d7c.zip
clean up handling of thread/nothread mode, locking
Diffstat (limited to 'src/thread')
-rw-r--r--src/thread/cancel_impl.c2
-rw-r--r--src/thread/pthread_create.c22
-rw-r--r--src/thread/pthread_setcancelstate.c2
3 files changed, 10 insertions, 16 deletions
diff --git a/src/thread/cancel_impl.c b/src/thread/cancel_impl.c
index 2d2bb572..1f4ff90c 100644
--- a/src/thread/cancel_impl.c
+++ b/src/thread/cancel_impl.c
@@ -17,7 +17,7 @@ long (__syscall_cp)(long nr, long u, long v, long w, long x, long y, long z)
uintptr_t old_sp, old_ip;
long r;
- if (!libc.lock || (self = __pthread_self())->canceldisable)
+ if (!libc.threaded || (self = __pthread_self())->canceldisable)
return __syscall(nr, u, v, w, x, y, z);
old_sp = self->cp_sp;
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index 844d7bf9..8e3a4a26 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -44,18 +44,6 @@ void __pthread_unwind_next(struct __ptcb *cb)
__syscall(SYS_exit, 0);
}
-static void init_threads()
-{
- sigset_t set;
- libc.lock = __lock;
- libc.lockfile = __lockfile;
-
- sigemptyset(&set);
- sigaddset(&set, SIGSYSCALL);
- sigaddset(&set, SIGCANCEL);
- __libc_sigprocmask(SIG_UNBLOCK, &set, 0);
-}
-
static int start(void *p)
{
struct pthread *self = p;
@@ -79,7 +67,6 @@ weak_alias(dummy, __pthread_tsd_size);
int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(void *), void *arg)
{
- static int init;
int ret;
size_t size, guard;
struct pthread *self = pthread_self(), *new;
@@ -87,7 +74,14 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo
const pthread_attr_t default_attr = { 0 };
if (!self) return ENOSYS;
- if (!init && ++init) init_threads();
+ if (!libc.threaded) {
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGSYSCALL);
+ sigaddset(&set, SIGCANCEL);
+ __libc_sigprocmask(SIG_UNBLOCK, &set, 0);
+ libc.threaded = 1;
+ }
if (!attr) attr = &default_attr;
guard = ROUND(attr->_a_guardsize + DEFAULT_GUARD_SIZE);
diff --git a/src/thread/pthread_setcancelstate.c b/src/thread/pthread_setcancelstate.c
index 6722541a..ebb6eba4 100644
--- a/src/thread/pthread_setcancelstate.c
+++ b/src/thread/pthread_setcancelstate.c
@@ -3,7 +3,7 @@
int pthread_setcancelstate(int new, int *old)
{
if (new > 1U) return EINVAL;
- if (libc.lock) {
+ if (libc.threaded) {
struct pthread *self = __pthread_self();
if (old) *old = self->canceldisable;
self->canceldisable = new;