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.14 PTH_1_0b7:1.14 PTH_1_0b6:1.14 PTH_1_0b5:1.14 PTH_1_0b4:1.12 PTH_1_0b3:1.10 PTH_1_0b2:1.10 PTH_1_0b1:1.9 PTH_0_9_21:1.7 PTH_0_9_20:1.7 PTH_0_9_19:1.6 PTH_0_9_18:1.5; locks; strict; comment @ * @; 1.31 date 2007.01.01.18.23.52; author rse; state Exp; branches; next 1.30; commitid 9DhdiirNzQPBIP0s; 1.30 date 2006.06.08.17.54.52; author rse; state Exp; branches; next 1.29; commitid x8N3mLVdQgkbdeAr; 1.29 date 2004.12.31.19.34.45; author rse; state Exp; branches; next 1.28; 1.28 date 2004.07.13.10.50.49; author rse; state Exp; branches; next 1.27; 1.27 date 2003.01.01.15.49.11; author rse; state Exp; branches; next 1.26; 1.26 date 2002.10.24.15.21.13; author rse; state Exp; branches; next 1.25; 1.25 date 2002.01.27.11.03.40; author rse; state Exp; branches; next 1.24; 1.24 date 2001.03.24.14.51.04; author rse; state Exp; branches; next 1.23; 1.23 date 99.12.30.21.59.00; author rse; state Exp; branches; next 1.22; 1.22 date 99.12.15.18.14.08; author rse; state Exp; branches; next 1.21; 1.21 date 99.11.09.08.11.31; author rse; state Exp; branches; next 1.20; 1.20 date 99.11.01.10.27.19; author rse; state Exp; branches; next 1.19; 1.19 date 99.10.31.11.46.12; author rse; state Exp; branches 1.19.2.1; next 1.18; 1.18 date 99.10.22.07.13.26; author rse; state Exp; branches; next 1.17; 1.17 date 99.09.17.08.01.54; author rse; state Exp; branches; next 1.16; 1.16 date 99.08.30.13.10.24; author rse; state Exp; branches; next 1.15; 1.15 date 99.08.19.15.08.52; author rse; state Exp; branches; next 1.14; 1.14 date 99.07.09.06.19.27; author rse; state Exp; branches; next 1.13; 1.13 date 99.07.08.15.01.18; author rse; state Exp; branches; next 1.12; 1.12 date 99.07.08.10.34.01; author rse; state Exp; branches; next 1.11; 1.11 date 99.07.08.10.19.10; author rse; state Exp; branches; next 1.10; 1.10 date 99.07.04.12.05.35; author rse; state Exp; branches; next 1.9; 1.9 date 99.06.27.15.40.30; author rse; state Exp; branches; next 1.8; 1.8 date 99.06.27.15.38.04; author rse; state Exp; branches; next 1.7; 1.7 date 99.06.24.12.07.32; author rse; state Exp; branches; next 1.6; 1.6 date 99.06.21.14.24.47; author rse; state Exp; branches; next 1.5; 1.5 date 99.06.20.10.01.05; author rse; state Exp; branches; next 1.4; 1.4 date 99.06.20.09.58.57; author rse; state Exp; branches; next 1.3; 1.3 date 99.06.20.09.44.27; author rse; state Exp; branches; next 1.2; 1.2 date 99.06.19.16.00.37; author rse; state Exp; branches; next 1.1; 1.1 date 99.06.19.15.59.54; author rse; state Exp; branches; next ; 1.19.2.1 date 99.11.01.10.24.59; author rse; state Exp; branches; next ; desc @@ 1.31 log @Adjusted all copyright messages for new year 2007. @ text @/* ** GNU Pth - The GNU Portable Threads ** Copyright (c) 1999-2007 Ralf S. Engelschall ** ** This file is part of GNU Pth, a non-preemptive thread scheduling ** library which can be found at http://www.gnu.org/software/pth/. ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License as published by the Free Software Foundation; either ** version 2.1 of the License, or (at your option) any later version. ** ** This library is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** Lesser General Public License for more details. ** ** You should have received a copy of the GNU Lesser General Public ** License along with this library; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ** USA, or contact Ralf S. Engelschall . ** ** pth_cancel.c: Pth thread cancellation */ /* ``Study it forever and you'll still wonder. Fly it once and you'll know.'' -- Henry Spencer */ #include "pth_p.h" /* set cancellation state */ void pth_cancel_state(int newstate, int *oldstate) { if (oldstate != NULL) *oldstate = pth_current->cancelstate; if (newstate != 0) pth_current->cancelstate = newstate; return; } /* enter a cancellation point */ void pth_cancel_point(void) { if ( pth_current->cancelreq == TRUE && pth_current->cancelstate & PTH_CANCEL_ENABLE) { /* avoid looping if cleanup handlers contain cancellation points */ pth_current->cancelreq = FALSE; pth_debug2("pth_cancel_point: terminating cancelled thread \"%s\"", pth_current->name); pth_exit(PTH_CANCELED); } return; } /* cancel a thread (the friendly way) */ int pth_cancel(pth_t thread) { pth_pqueue_t *q; if (thread == NULL) return pth_error(FALSE, EINVAL); /* the current thread cannot be cancelled */ if (thread == pth_current) return pth_error(FALSE, EINVAL); /* the thread has to be at least still alive */ if (thread->state == PTH_STATE_DEAD) return pth_error(FALSE, EPERM); /* now mark the thread as cancelled */ thread->cancelreq = TRUE; /* when cancellation is enabled in async mode we cancel the thread immediately */ if ( thread->cancelstate & PTH_CANCEL_ENABLE && thread->cancelstate & PTH_CANCEL_ASYNCHRONOUS) { /* remove thread from its queue */ switch (thread->state) { case PTH_STATE_NEW: q = &pth_NQ; break; case PTH_STATE_READY: q = &pth_RQ; break; case PTH_STATE_WAITING: q = &pth_WQ; break; default: q = NULL; } if (q == NULL) return pth_error(FALSE, ESRCH); if (!pth_pqueue_contains(q, thread)) return pth_error(FALSE, ESRCH); pth_pqueue_delete(q, thread); /* execute cleanups */ pth_thread_cleanup(thread); /* and now either kick it out or move it to dead queue */ if (!thread->joinable) { pth_debug2("pth_cancel: kicking out cancelled thread \"%s\" immediately", thread->name); pth_tcb_free(thread); } else { pth_debug2("pth_cancel: moving cancelled thread \"%s\" to dead queue", thread->name); thread->join_arg = PTH_CANCELED; thread->state = PTH_STATE_DEAD; pth_pqueue_insert(&pth_DQ, PTH_PRIO_STD, thread); } } return TRUE; } /* abort a thread (the cruel way) */ int pth_abort(pth_t thread) { if (thread == NULL) return pth_error(FALSE, EINVAL); /* the current thread cannot be aborted */ if (thread == pth_current) return pth_error(FALSE, EINVAL); if (thread->state == PTH_STATE_DEAD && thread->joinable) { /* if thread is already terminated, just join it */ if (!pth_join(thread, NULL)) return FALSE; } else { /* else force it to be detached and cancel it asynchronously */ thread->joinable = FALSE; thread->cancelstate = (PTH_CANCEL_ENABLE|PTH_CANCEL_ASYNCHRONOUS); if (!pth_cancel(thread)) return FALSE; } return TRUE; } @ 1.30 log @Adjusted all copyright messages for new year 2006 @ text @d3 1 a3 1 ** Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.29 log @Adjusted all copyright messages for new year 2005. @ text @d3 1 a3 1 ** Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.28 log @Adjusted all copyright messages for new year 2004. @ text @d3 1 a3 1 ** Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.27 log @Adjusted all copyright messages for new year 2003. @ text @d3 1 a3 1 ** Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.26 log @Internally switch from "errno_shield {...}" to "pth_shield {...}" and from "return_errno(..)" to "return pth_error(...)" in order to make the internal error handling a little bit more consistent. @ text @d3 1 a3 1 ** Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.25 log @bump copyright year @ text @d59 1 a59 1 return_errno(FALSE, EINVAL); d63 1 a63 1 return_errno(FALSE, EINVAL); d67 1 a67 1 return_errno(FALSE, EPERM); d84 1 a84 1 return_errno(FALSE, ESRCH); d86 1 a86 1 return_errno(FALSE, ESRCH); d111 1 a111 1 return_errno(FALSE, EINVAL); d115 1 a115 1 return_errno(FALSE, EINVAL); @ 1.24 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.23 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.22 log @*** empty log message *** @ text @d3 1 a3 1 ** Copyright (c) 1999 Ralf S. Engelschall @ 1.21 log @*** empty log message *** @ text @d89 2 a90 10 /* run the cleanup handlers */ if (thread->cleanups != NULL) pth_cleanup_popall(thread, TRUE); /* run the specific data destructors */ if (thread->data_value != NULL) pth_key_destroydata(thread); /* release still acquired mutex variables */ pth_mutex_releaseall(thread); @ 1.20 log @*** empty log message *** @ text @d43 1 a43 1 if ( pth_current->cancelreq == TRUE d73 1 a73 1 if ( thread->cancelstate & PTH_CANCEL_ENABLE @ 1.19 log @*** empty log message *** @ text @d2 1 a2 2 ** pth_cancel.c -- Pth thread cancellation ** d22 2 @ 1.19.2.1 log @*** empty log message *** @ text @d2 2 a3 1 ** GNU Pth - The GNU Portable Threads a22 2 ** ** pth_cancel.c: Pth thread cancellation @ 1.18 log @*** empty log message *** @ text @d12 1 a12 1 ** version 2 of the License, or (at your option) any later version. @ 1.17 log @*** empty log message *** @ text @d44 2 @ 1.16 log @*** empty log message *** @ text @d10 1 a10 1 ** modify it under the terms of the GNU Library General Public d17 1 a17 1 ** Library General Public License for more details. d19 1 a19 1 ** You should have received a copy of the GNU Library General Public @ 1.15 log @*** empty log message *** @ text @d75 3 a77 3 case PTH_STATE_NEW: q = &pth_NQ; case PTH_STATE_READY: q = &pth_RQ; case PTH_STATE_WAITING: q = &pth_WQ; @ 1.14 log @*** empty log message *** @ text @d24 3 a26 1 @ 1.13 log @*** empty log message *** @ text @d120 1 a120 1 if (thread->state == PTH_STATE_DEAD && thread->joinable) d124 1 @ 1.12 log @*** empty log message *** @ text @d48 1 a48 1 /* cancel a thread */ d106 24 @ 1.11 log @*** empty log message *** @ text @d2 1 a2 1 ** pth_cancel.c -- PTH thread cancellation @ 1.10 log @*** empty log message *** @ text @d6 2 a7 2 ** This file is part of PTH, a non-preemptive thread scheduling library ** which can be found at http://www.gnu.org/software/pth/. @ 1.9 log @*** empty log message *** @ text @d7 1 a7 1 ** which can be found at http://www.engelschall.com/sw/pth/. @ 1.8 log @*** empty log message *** @ text @d61 1 a61 1 if (thread->state == pth_state_dead) d73 3 a75 3 case pth_state_new: q = &pth_NQ; case pth_state_ready: q = &pth_RQ; case pth_state_waiting: q = &pth_WQ; d103 1 a103 1 thread->state = pth_state_dead; @ 1.7 log @*** empty log message *** @ text @d96 1 a96 1 if (thread->flags & PTH_FLAG_NOJOIN) { @ 1.6 log @*** empty log message *** @ text @d54 5 a58 5 return FALSE; /* the scheduler or current threads cannot be cancelled */ if (thread == pth_sched || thread == pth_current) return FALSE; d62 1 a62 1 return FALSE; d79 1 a79 1 return FALSE; d81 1 a81 1 return FALSE; @ 1.5 log @*** empty log message *** @ text @d92 3 @ 1.4 log @*** empty log message *** @ text @d42 1 a42 2 pth_debug2("pth_cancel_point: terminating due to pending cancellation request " "for thread \"%s\"", pth_current->name); @ 1.3 log @*** empty log message *** @ text @d41 3 a43 1 && pth_current->cancelstate & PTH_CANCEL_ENABLE) d45 1 @ 1.2 log @*** empty log message *** @ text @d32 1 a32 1 if (newstate != NULL) @ 1.1 log @*** empty log message *** @ text @d65 1 a65 1 /* when cancellation is enabled in async mode we cancel the thread now */ d68 1 @