xref: /haiku/src/system/libroot/posix/pthread/pthread_cleanup.cpp (revision a635399b0744555fe9f3fc01d6f58ff29d3bc075)
1*a635399bSAxel Dörfler /*
2*a635399bSAxel Dörfler  * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3*a635399bSAxel Dörfler  * Distributed under the terms of the MIT License.
4*a635399bSAxel Dörfler  */
5*a635399bSAxel Dörfler 
6*a635399bSAxel Dörfler 
7*a635399bSAxel Dörfler #include "pthread_private.h"
8*a635399bSAxel Dörfler 
9*a635399bSAxel Dörfler 
10*a635399bSAxel Dörfler void
11*a635399bSAxel Dörfler __pthread_cleanup_push_handler(__pthread_cleanup_handler* handler)
12*a635399bSAxel Dörfler {
13*a635399bSAxel Dörfler 	pthread_thread* thread = __get_pthread();
14*a635399bSAxel Dörfler 	if (thread == NULL)
15*a635399bSAxel Dörfler 		return;
16*a635399bSAxel Dörfler 
17*a635399bSAxel Dörfler 	handler->previous = thread->cleanup_handlers;
18*a635399bSAxel Dörfler 	thread->cleanup_handlers = handler;
19*a635399bSAxel Dörfler }
20*a635399bSAxel Dörfler 
21*a635399bSAxel Dörfler 
22*a635399bSAxel Dörfler __pthread_cleanup_handler*
23*a635399bSAxel Dörfler __pthread_cleanup_pop_handler(void)
24*a635399bSAxel Dörfler {
25*a635399bSAxel Dörfler 	pthread_thread* thread = __get_pthread();
26*a635399bSAxel Dörfler 	if (thread == NULL)
27*a635399bSAxel Dörfler 		return NULL;
28*a635399bSAxel Dörfler 
29*a635399bSAxel Dörfler 	__pthread_cleanup_handler* handler = thread->cleanup_handlers;
30*a635399bSAxel Dörfler 	thread->cleanup_handlers = handler->previous;
31*a635399bSAxel Dörfler 
32*a635399bSAxel Dörfler 	return handler;
33*a635399bSAxel Dörfler }
34*a635399bSAxel Dörfler 
35