static void vcos_thread_wrapper(int argc, void *arg) #endif { int i; void *ret; VCOS_THREAD_T *thread = (VCOS_THREAD_T *)arg; vcos_assert(thread->magic == VCOS_THREAD_MAGIC); #ifdef VCOS_WANT_TLS_EMULATION vcos_tls_thread_register(&thread->_tls); #endif if (thread->legacy) { LEGACY_ENTRY_FN_T fn = (LEGACY_ENTRY_FN_T)thread->entry; fn(0,thread->arg); ret = 0; } else { ret = thread->entry(thread->arg); } // call termination functions for (i=0; i<VCOS_MAX_EXIT_HANDLERS; i++) { if (thread->at_exit[i].pfn) { thread->at_exit[i].pfn(thread->at_exit[i].cxt); } } thread->exit_data = ret; vcos_semaphore_post(&thread->wait); }
/** Wrapper function around the real thread function. Posts the semaphore * when completed. */ static int vcos_thread_wrapper(void *arg) { void *ret; VCOS_THREAD_T *thread = arg; vcos_assert(thread->magic == VCOS_THREAD_MAGIC); thread->thread.thread = current; vcos_add_thread(thread); #ifdef VCOS_WANT_TLS_EMULATION vcos_tls_thread_register(&thread->_tls); #endif if (thread->legacy) { LEGACY_ENTRY_FN_T fn = (LEGACY_ENTRY_FN_T)thread->entry; fn(0,thread->arg); ret = 0; } else { ret = thread->entry(thread->arg); } thread->exit_data = ret; vcos_remove_thread(current); /* For join and cleanup */ vcos_semaphore_post(&thread->wait); return 0; }
VCOS_STATUS_T _vcos_thread_create_attach(VCOS_THREAD_T *thread, const char *name) { VCOS_STATUS_T status; status = create_base(thread, name); if (status != VCOS_SUCCESS) goto fail_base; status = _vcos_llthread_create_attach(&thread->thread); if (status != VCOS_SUCCESS) goto fail_llthread; #ifdef VCOS_WANT_TLS_EMULATION vcos_tls_thread_register(&thread->_tls); #endif return VCOS_SUCCESS; fail_llthread: delete_base(thread); fail_base: return status; }