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