summaryrefslogtreecommitdiff
path: root/lib/libpthread/uthread/uthread_cancel.c
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2001-08-21 19:24:54 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2001-08-21 19:24:54 +0000
commit16d25a545116e8f7dfac9140d654821d417a8eba (patch)
tree3f00c8ca19e17cde8d276fc02cb5f85fa1d8e5f3 /lib/libpthread/uthread/uthread_cancel.c
parent3cfb4c4b00852105397632dba44ff455c6e1cb8f (diff)
Start syncing with FreeBSD:
o Implement _get_curthread() and _set_curthread(). Use it where possible. o Add missing _thread_[enter|leave]_cancellation_point(). o Add a couple of not yet used vars to pthread_private.h. o Remove return's from void functions. This is by no means complete, but instead of doing a big commit, i'll split it in small ones, minimizing diffs.
Diffstat (limited to 'lib/libpthread/uthread/uthread_cancel.c')
-rw-r--r--lib/libpthread/uthread/uthread_cancel.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/libpthread/uthread/uthread_cancel.c b/lib/libpthread/uthread/uthread_cancel.c
index e43e03bf00b..7428ee07ecb 100644
--- a/lib/libpthread/uthread/uthread_cancel.c
+++ b/lib/libpthread/uthread/uthread_cancel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_cancel.c,v 1.2 1999/11/25 07:01:32 d Exp $ */
+/* $OpenBSD: uthread_cancel.c,v 1.3 2001/08/21 19:24:53 fgsch Exp $ */
/*
* David Leonard <d@openbsd.org>, 1999. Public domain.
*/
@@ -64,24 +64,25 @@ pthread_setcancelstate(state, oldstate)
int state;
int *oldstate;
{
+ struct pthread *curthread = _get_curthread();
int ostate;
int ret;
- ostate = _thread_run->cancelstate;
+ ostate = curthread->cancelstate;
switch (state) {
case PTHREAD_CANCEL_ENABLE:
if (oldstate)
*oldstate = ostate;
- _thread_run->cancelstate = PTHREAD_CANCEL_ENABLE;
- if (_thread_run->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
+ curthread->cancelstate = PTHREAD_CANCEL_ENABLE;
+ if (curthread->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
_thread_cancellation_point();
ret = 0;
break;
case PTHREAD_CANCEL_DISABLE:
if (oldstate)
*oldstate = ostate;
- _thread_run->cancelstate = PTHREAD_CANCEL_DISABLE;
+ curthread->cancelstate = PTHREAD_CANCEL_DISABLE;
ret = 0;
break;
default:
@@ -97,22 +98,23 @@ pthread_setcanceltype(type, oldtype)
int type;
int *oldtype;
{
+ struct pthread *curthread = _get_curthread();
int otype;
int ret;
- otype = _thread_run->canceltype;
+ otype = curthread->canceltype;
switch (type) {
case PTHREAD_CANCEL_ASYNCHRONOUS:
if (oldtype)
*oldtype = otype;
- _thread_run->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
+ curthread->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
_thread_cancellation_point();
ret = 0;
break;
case PTHREAD_CANCEL_DEFERRED:
if (oldtype)
*oldtype = otype;
- _thread_run->canceltype = PTHREAD_CANCEL_DEFERRED;
+ curthread->canceltype = PTHREAD_CANCEL_DEFERRED;
ret = 0;
break;
default:
@@ -132,17 +134,19 @@ pthread_testcancel()
void
_thread_enter_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
/* Look for a cancellation before we block: */
_thread_cancellation_point();
- _thread_run->flags |= PTHREAD_FLAGS_CANCELPT;
+ curthread->flags |= PTHREAD_FLAGS_CANCELPT;
}
void
_thread_leave_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
- _thread_run->flags &=~ PTHREAD_FLAGS_CANCELPT;
+ curthread->flags &=~ PTHREAD_FLAGS_CANCELPT;
/* Look for a cancellation after we unblock: */
_thread_cancellation_point();
}
@@ -154,11 +158,12 @@ _thread_leave_cancellation_point()
void
_thread_cancellation_point()
{
+ struct pthread *curthread = _get_curthread();
- if ((_thread_run->cancelstate == PTHREAD_CANCEL_ENABLE) &&
- ((_thread_run->flags & (PTHREAD_FLAGS_CANCELED|PTHREAD_EXITING)) ==
+ if ((curthread->cancelstate == PTHREAD_CANCEL_ENABLE) &&
+ ((curthread->flags & (PTHREAD_FLAGS_CANCELED|PTHREAD_EXITING)) ==
PTHREAD_FLAGS_CANCELED)) {
- _thread_run->flags &=~ PTHREAD_FLAGS_CANCELED;
+ curthread->flags &=~ PTHREAD_FLAGS_CANCELED;
pthread_exit(PTHREAD_CANCELED);
PANIC("cancel");
}