* @brief Registers a cleanup handler to be executed when the calling thread terminates. * * The `pthread_cleanup_push` function registers a cleanup handler that is executed when the calling thread * is canceled or exits (either normally or via `pthread_exit`). The cleanup handler will be executed * in the reverse order of their registration. * * The cleanup handler can be used to release res
| 1229 | * @see pthread_cleanup_pop, pthread_cancel, pthread_exit |
| 1230 | */ |
| 1231 | void pthread_cleanup_push(void (*routine)(void *), void *arg) |
| 1232 | { |
| 1233 | _pthread_data_t *ptd; |
| 1234 | _pthread_cleanup_t *cleanup; |
| 1235 | |
| 1236 | if (rt_thread_self() == NULL) return; |
| 1237 | |
| 1238 | /* get pthread data from pthread_data of thread */ |
| 1239 | ptd = (_pthread_data_t *)rt_thread_self()->pthread_data; |
| 1240 | RT_ASSERT(ptd != RT_NULL); |
| 1241 | |
| 1242 | cleanup = (_pthread_cleanup_t *)rt_malloc(sizeof(_pthread_cleanup_t)); |
| 1243 | if (cleanup != RT_NULL) |
| 1244 | { |
| 1245 | cleanup->cleanup_func = routine; |
| 1246 | cleanup->parameter = arg; |
| 1247 | |
| 1248 | rt_enter_critical(); |
| 1249 | cleanup->next = ptd->cleanup; |
| 1250 | ptd->cleanup = cleanup; |
| 1251 | rt_exit_critical(); |
| 1252 | } |
| 1253 | } |
| 1254 | RTM_EXPORT(pthread_cleanup_push); |
| 1255 | |
| 1256 | /* |
no test coverage detected