/[pcsx2_0.9.7]/trunk/3rdparty/w32pthreads/pthread_setcanceltype.c
ViewVC logotype

Contents of /trunk/3rdparty/w32pthreads/pthread_setcanceltype.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 4020 byte(s)
committing r3113 initial commit again...
1 /*
2 * pthread_setcanceltype.c
3 *
4 * Description:
5 * POSIX thread functions related to thread cancellation.
6 *
7 * --------------------------------------------------------------------------
8 *
9 * Pthreads-win32 - POSIX Threads Library for Win32
10 * Copyright(C) 1998 John E. Bossom
11 * Copyright(C) 1999,2005 Pthreads-win32 contributors
12 *
13 * Contact Email: rpj@callisto.canberra.edu.au
14 *
15 * The current list of contributors is contained
16 * in the file CONTRIBUTORS included with the source
17 * code distribution. The list can also be seen at the
18 * following World Wide Web location:
19 * http://sources.redhat.com/pthreads-win32/contributors.html
20 *
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2 of the License, or (at your option) any later version.
25 *
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library in the file COPYING.LIB;
33 * if not, write to the Free Software Foundation, Inc.,
34 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
35 */
36
37 #include "ptw32pch.h"
38
39 int
40 pthread_setcanceltype (int type, int *oldtype)
41 /*
42 * ------------------------------------------------------
43 * DOCPUBLIC
44 * This function atomically sets the calling thread's
45 * cancelability type to 'type' and returns the previous
46 * cancelability type at the location referenced by
47 * 'oldtype'
48 *
49 * PARAMETERS
50 * type,
51 * oldtype
52 * PTHREAD_CANCEL_DEFERRED
53 * only deferred cancelation is allowed,
54 *
55 * PTHREAD_CANCEL_ASYNCHRONOUS
56 * Asynchronous cancellation is allowed
57 *
58 *
59 * DESCRIPTION
60 * This function atomically sets the calling thread's
61 * cancelability type to 'type' and returns the previous
62 * cancelability type at the location referenced by
63 * 'oldtype'
64 *
65 * NOTES:
66 * 1) Use with caution; most code is not safe for use
67 * with asynchronous cancelability.
68 *
69 * COMPATIBILITY ADDITIONS
70 * If 'oldtype' is NULL then the previous type is not returned
71 * but the function still succeeds. (Solaris)
72 *
73 * RESULTS
74 * 0 successfully set cancelability type,
75 * EINVAL 'type' is invalid
76 *
77 * ------------------------------------------------------
78 */
79 {
80 int result = 0;
81 pthread_t self = pthread_self ();
82 ptw32_thread_t * sp = (ptw32_thread_t *) self.p;
83
84 if (sp == NULL
85 || (type != PTHREAD_CANCEL_DEFERRED
86 && type != PTHREAD_CANCEL_ASYNCHRONOUS))
87 {
88 return EINVAL;
89 }
90
91 /*
92 * Lock for async-cancel safety.
93 */
94 (void) pthread_mutex_lock (&sp->cancelLock);
95
96 if (oldtype != NULL)
97 {
98 *oldtype = sp->cancelType;
99 }
100
101 sp->cancelType = type;
102
103 /*
104 * Check if there is a pending asynchronous cancel
105 */
106 if (sp->cancelState == PTHREAD_CANCEL_ENABLE
107 && type == PTHREAD_CANCEL_ASYNCHRONOUS
108 && WaitForSingleObject (sp->cancelEvent, 0) == WAIT_OBJECT_0)
109 {
110 sp->state = PThreadStateCanceling;
111 sp->cancelState = PTHREAD_CANCEL_DISABLE;
112 ResetEvent (sp->cancelEvent);
113 (void) pthread_mutex_unlock (&sp->cancelLock);
114 ptw32_throw (PTW32_EPS_CANCEL);
115
116 /* Never reached */
117 }
118
119 (void) pthread_mutex_unlock (&sp->cancelLock);
120
121 return (result);
122
123 } /* pthread_setcanceltype */

  ViewVC Help
Powered by ViewVC 1.1.22