* @brief Unregisters a cleanup handler and optionally executes it. * * The `pthread_cleanup_pop` function unregisters a cleanup handler that was previously registered * using `pthread_cleanup_push`. If the `execute` parameter is non-zero, the cleanup handler is executed * at the point where the thread terminates or is canceled. * * If `execute` is zero, the handler is unregistered without be
| 1173 | * @see pthread_cleanup_push, pthread_exit, pthread_cancel |
| 1174 | */ |
| 1175 | void pthread_cleanup_pop(int execute) |
| 1176 | { |
| 1177 | _pthread_data_t *ptd; |
| 1178 | _pthread_cleanup_t *cleanup; |
| 1179 | |
| 1180 | if (rt_thread_self() == NULL) return; |
| 1181 | |
| 1182 | /* get pthread data from pthread_data of thread */ |
| 1183 | ptd = (_pthread_data_t *)rt_thread_self()->pthread_data; |
| 1184 | RT_ASSERT(ptd != RT_NULL); |
| 1185 | |
| 1186 | if (execute) |
| 1187 | { |
| 1188 | rt_enter_critical(); |
| 1189 | cleanup = ptd->cleanup; |
| 1190 | if (cleanup) |
| 1191 | ptd->cleanup = cleanup->next; |
| 1192 | rt_exit_critical(); |
| 1193 | |
| 1194 | if (cleanup) |
| 1195 | { |
| 1196 | cleanup->cleanup_func(cleanup->parameter); |
| 1197 | |
| 1198 | rt_free(cleanup); |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | RTM_EXPORT(pthread_cleanup_pop); |
| 1203 | |
| 1204 | /** |
no test coverage detected