about summary refs log tree commit diff
path: root/src/thread
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread')
-rw-r--r--src/thread/pthread_create.c16
-rw-r--r--src/thread/pthread_setcancelstate.c4
2 files changed, 15 insertions, 5 deletions
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index 284b45a0..52487001 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -57,9 +57,19 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
 static void cancelpt(int x)
 {
 	struct pthread *self = __pthread_self();
-	if (self->canceldisable) return;
-	if ((self->cancelpoint+=x)==1 && x>=0 && self->cancel)
-		docancel(self);
+	switch (x) {
+	case 1:
+		self->cancelpoint++;
+	case 0:
+		if (self->cancel && self->cancelpoint==1 && !self->canceldisable)
+			docancel(self);
+		break;
+	case -1:
+		self->cancelpoint--;
+		break;
+	default:
+		self->canceldisable += x;
+	}
 }
 
 /* "rsyscall" is a mechanism by which a thread can synchronously force all
diff --git a/src/thread/pthread_setcancelstate.c b/src/thread/pthread_setcancelstate.c
index 23c38851..a85cc800 100644
--- a/src/thread/pthread_setcancelstate.c
+++ b/src/thread/pthread_setcancelstate.c
@@ -3,8 +3,8 @@
 int pthread_setcancelstate(int new, int *old)
 {
 	struct pthread *self = pthread_self();
-	if (old) *old = self->canceldisable;
+	if (old) *old = self->canceldisable & 1;
 	if ((unsigned)new > 1) return EINVAL;
-	self->canceldisable = new;
+	self->canceldisable = (self->canceldisable & ~1) | new;
 	return 0;
 }