|
31 | 31 | #include <stdlib.h>
|
32 | 32 | #include <unistd.h>
|
33 | 33 |
|
| 34 | +#include <nuttx/tls.h> |
| 35 | +#include <nuttx/pthread.h> |
| 36 | + |
34 | 37 | #if defined(CONFIG_BUILD_FLAT) || !defined(__KERNEL__)
|
35 | 38 |
|
36 | 39 | /****************************************************************************
|
@@ -86,6 +89,21 @@ FAR void *__dso_handle = &__dso_handle;
|
86 | 89 |
|
87 | 90 | void exit(int status)
|
88 | 91 | {
|
| 92 | + /* Mark the pthread as non-cancelable to avoid additional calls to |
| 93 | + * pthread_exit() due to any cancellation point logic that might get |
| 94 | + * kicked off by actions taken during pthread_exit processing. |
| 95 | + */ |
| 96 | + |
| 97 | + task_setcancelstate(TASK_CANCEL_DISABLE, NULL); |
| 98 | + |
| 99 | +#ifdef CONFIG_PTHREAD_CLEANUP |
| 100 | + pthread_cleanup_popall(tls_get_info()); |
| 101 | +#endif |
| 102 | + |
| 103 | +#if CONFIG_TLS_NELEM > 0 |
| 104 | + tls_destruct(); |
| 105 | +#endif |
| 106 | + |
89 | 107 | /* Run the registered exit functions */
|
90 | 108 |
|
91 | 109 | atexit_call_exitfuncs(status, false);
|
@@ -120,6 +138,21 @@ void exit(int status)
|
120 | 138 |
|
121 | 139 | void quick_exit(int status)
|
122 | 140 | {
|
| 141 | + /* Mark the pthread as non-cancelable to avoid additional calls to |
| 142 | + * pthread_exit() due to any cancellation point logic that might get |
| 143 | + * kicked off by actions taken during pthread_exit processing. |
| 144 | + */ |
| 145 | + |
| 146 | + task_setcancelstate(TASK_CANCEL_DISABLE, NULL); |
| 147 | + |
| 148 | +#ifdef CONFIG_PTHREAD_CLEANUP |
| 149 | + pthread_cleanup_popall(tls_get_info()); |
| 150 | +#endif |
| 151 | + |
| 152 | +#if CONFIG_TLS_NELEM > 0 |
| 153 | + tls_destruct(); |
| 154 | +#endif |
| 155 | + |
123 | 156 | /* Run the registered exit functions */
|
124 | 157 |
|
125 | 158 | atexit_call_exitfuncs(status, true);
|
|
0 commit comments