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