5 * This translation unit implements routines associated
6 * with cleaning up threads.
9 * --------------------------------------------------------------------------
11 * Pthreads-win32 - POSIX Threads Library for Win32
12 * Copyright(C) 1998 John E. Bossom
13 * Copyright(C) 1999,2005 Pthreads-win32 contributors
15 * Contact Email: rpj@callisto.canberra.edu.au
17 * The current list of contributors is contained
18 * in the file CONTRIBUTORS included with the source
19 * code distribution. The list can also be seen at the
20 * following World Wide Web location:
21 * http://sources.redhat.com/pthreads-win32/contributors.html
23 * This library is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU Lesser General Public
25 * License as published by the Free Software Foundation; either
26 * version 2 of the License, or (at your option) any later version.
28 * This library is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * Lesser General Public License for more details.
33 * You should have received a copy of the GNU Lesser General Public
34 * License along with this library in the file COPYING.LIB;
35 * if not, write to the Free Software Foundation, Inc.,
36 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
40 #include "implement.h"
44 * The functions ptw32_pop_cleanup and ptw32_push_cleanup
45 * are implemented here for applications written in C with no
46 * SEH or C++ destructor support.
50 ptw32_pop_cleanup (int execute
)
52 * ------------------------------------------------------
54 * This function pops the most recently pushed cleanup
55 * handler. If execute is nonzero, then the cleanup handler
56 * is executed if non-null.
60 * if nonzero, execute the cleanup handler
64 * This function pops the most recently pushed cleanup
65 * handler. If execute is nonzero, then the cleanup handler
66 * is executed if non-null.
67 * NOTE: specify 'execute' as nonzero to avoid duplication
68 * of common cleanup code.
73 * ------------------------------------------------------
76 ptw32_cleanup_t
*cleanup
;
78 cleanup
= (ptw32_cleanup_t
*) pthread_getspecific (ptw32_cleanupKey
);
82 if (execute
&& (cleanup
->routine
!= NULL
))
85 (*cleanup
->routine
) (cleanup
->arg
);
89 pthread_setspecific (ptw32_cleanupKey
, (void *) cleanup
->prev
);
95 } /* ptw32_pop_cleanup */
99 ptw32_push_cleanup (ptw32_cleanup_t
* cleanup
,
100 ptw32_cleanup_callback_t routine
, void *arg
)
102 * ------------------------------------------------------
104 * This function pushes a new cleanup handler onto the thread's stack
105 * of cleanup handlers. Each cleanup handler pushed onto the stack is
106 * popped and invoked with the argument 'arg' when
107 * a) the thread exits by calling 'pthread_exit',
108 * b) when the thread acts on a cancellation request,
109 * c) or when the thread calls pthread_cleanup_pop with a nonzero
114 * a pointer to an instance of pthread_cleanup_t,
117 * pointer to a cleanup handler,
120 * parameter to be passed to the cleanup handler
124 * This function pushes a new cleanup handler onto the thread's stack
125 * of cleanup handlers. Each cleanup handler pushed onto the stack is
126 * popped and invoked with the argument 'arg' when
127 * a) the thread exits by calling 'pthread_exit',
128 * b) when the thread acts on a cancellation request,
129 * c) or when the thrad calls pthread_cleanup_pop with a nonzero
131 * NOTE: pthread_push_cleanup, ptw32_pop_cleanup must be paired
132 * in the same lexical scope.
135 * pthread_cleanup_t *
136 * pointer to the previous cleanup
138 * ------------------------------------------------------
141 cleanup
->routine
= routine
;
144 cleanup
->prev
= (ptw32_cleanup_t
*) pthread_getspecific (ptw32_cleanupKey
);
146 pthread_setspecific (ptw32_cleanupKey
, (void *) cleanup
);
148 } /* ptw32_push_cleanup */