MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pthread_cleanup_push

Function pthread_cleanup_push

components/libc/posix/pthreads/pthread.c:1231–1253  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

1229 * @see pthread_cleanup_pop, pthread_cancel, pthread_exit
1230 */
1231void 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}
1254RTM_EXPORT(pthread_cleanup_push);
1255
1256/*

Callers 1

searchFunction · 0.85

Calls 4

rt_thread_selfFunction · 0.85
rt_mallocFunction · 0.85
rt_enter_criticalFunction · 0.50
rt_exit_criticalFunction · 0.50

Tested by

no test coverage detected