pthread_cleanup.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 RenĂ© Kijewski <rene.kijewski@fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
27 {
30 
32  void (*__routine)(void *arg);
33 
35  void *__arg;
37 
44 
52 
53 /*
54  * Notice: `pthread_cleanup_*` has to be defined as a macro, because the cleanup
55  * stack needs extra data. The standard explicitly allows defining these
56  * functions as macros. The alternative would be malloc.
57  */
58 
71 #define pthread_cleanup_push(ROUTINE, ARG) \
72  do { \
73  __extension__ __pthread_cleanup_datum_t ____datum__ = { \
74  .__routine = (ROUTINE), \
75  .__arg = (ARG), \
76  }; \
77  __extension__ int ____execute__ = 1; \
78  __pthread_cleanup_push(&____datum__); \
79  do { \
80  do { } while (0)
81 
87 #define pthread_cleanup_pop(EXECUTE) \
88  ____execute__ = (EXECUTE); \
89  } while (0); \
90  __pthread_cleanup_pop(&____datum__, ____execute__); \
91  } while (0)
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
void __pthread_cleanup_push(__pthread_cleanup_datum_t *datum)
Internal function to be called by pthread_cleanup_push()
struct __pthread_cleanup_datum __pthread_cleanup_datum_t
Internal structure for pthread_cleanup_push()
void __pthread_cleanup_pop(__pthread_cleanup_datum_t *datum, int execute)
Internal function to be called by pthread_cleanup_push()
Internal structure for pthread_cleanup_push()
void(* __routine)(void *arg)
Cleanup routine to call.
void * __arg
Argument to supply.
struct __pthread_cleanup_datum * __next
Cleanup handler to call next.