VCOS_STATUS_T vcos_platform_init(void) { VCOS_STATUS_T st; uint32_t flags = 0; st = _vcos_named_semaphore_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_NAMED_SEM; st = vcos_once(¤t_thread_key_once, current_thread_key_init); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; /* Initialise a VCOS wrapper for the thread which called vcos_init. */ st = vcos_semaphore_create(&vcos_thread_main.suspend, NULL, 0); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MAIN_SEM; #ifdef WIN32_KERN vcos_thread_main.thread = PsGetCurrentThreadId(); // TODO Implement thread context for kernel mode #else int pst; vcos_thread_main.thread = GetCurrentThread(); // For windows zero return value is failure pst = TlsSetValue(_vcos_thread_current_key, &vcos_thread_main); if (!vcos_verify(pst != 0)) { st = VCOS_EINVAL; goto end; } #endif st = vcos_msgq_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MSGQ; vcos_logging_init(); end: if (st != VCOS_SUCCESS) vcos_term(flags); return st; }
void vcos_platform_deinit(void) { vcos_term(VCOS_INIT_ALL); }
VCOS_STATUS_T vcos_platform_init(void) { VCOS_STATUS_T st; uint32_t flags = 0; int pst; st = _vcos_named_semaphore_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_NAMED_SEM; #ifdef HAVE_MTRACE /* enable glibc memory debugging, if the environment * variable MALLOC_TRACE names a valid file. */ mtrace(); #endif #ifdef ANDROID st = vcos_mutex_create(&printf_lock, "printf"); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_PRINTF_LOCK; #endif st = vcos_once(¤t_thread_key_once, current_thread_key_init); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; /* Initialise a VCOS wrapper for the thread which called vcos_init. */ st = vcos_semaphore_create(&vcos_thread_main.suspend, NULL, 0); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MAIN_SEM; vcos_thread_main.thread = pthread_self(); pst = pthread_setspecific(_vcos_thread_current_key, &vcos_thread_main); if (!vcos_verify(pst == 0)) { st = VCOS_EINVAL; goto end; } st = vcos_msgq_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MSGQ; vcos_logging_init(); end: if (st != VCOS_SUCCESS) vcos_term(flags); return st; }
void vcos_platform_deinit(void) { vcos_term((uint32_t)VCOS_INIT_ALL); }