summaryrefslogtreecommitdiff
path: root/src/thread/pthread_setcanceltype.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-17 13:21:13 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-17 13:21:13 -0400
commitebf82447be4b30bedc19ad868c3a0662b1ba596d (patch)
tree014a9584255a078cee6c99704306287ab13791f8 /src/thread/pthread_setcanceltype.c
parent02eff258c6a39746db287e20c142153e80c81bac (diff)
downloadmusl-ebf82447be4b30bedc19ad868c3a0662b1ba596d.tar.gz
optimize cancellation enable/disable code
the goal is to be able to use pthread_setcancelstate internally in the implementation, whenever a function might want to use functions which are cancellation points but avoid becoming a cancellation point itself. i could have just used a separate internal function for temporarily inhibiting cancellation, but the solution in this commit is better because (1) it's one less implementation-specific detail in functions that need to use it, and (2) application code can also get the same benefit. previously, pthread_setcancelstate dependend on pthread_self, which would pull in unwanted thread setup overhead for non-threaded programs. now, it temporarily stores the state in the global libc struct if threads have not been initialized, and later moves it if needed. this way we can instead use __pthread_self, which has no dependencies and assumes that the thread register is already valid.
Diffstat (limited to 'src/thread/pthread_setcanceltype.c')
-rw-r--r--src/thread/pthread_setcanceltype.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/thread/pthread_setcanceltype.c b/src/thread/pthread_setcanceltype.c
index c73db22f..7eb543a8 100644
--- a/src/thread/pthread_setcanceltype.c
+++ b/src/thread/pthread_setcanceltype.c
@@ -3,8 +3,8 @@
int pthread_setcanceltype(int new, int *old)
{
struct pthread *self = pthread_self();
+ if (new > 1U) return EINVAL;
if (old) *old = self->cancelasync;
- if ((unsigned)new > 1) return EINVAL;
self->cancelasync = new;
return 0;
}