VOS_Mutex *VOS_CreateMutex(void ) { ULONG ulResult = VOS_OK ; VOS_Mutex *pstMutex = VOS_NULL ; pstMutex = (VOS_Mutex *) VOS_malloc (sizeof(VOS_Mutex));//lint !e838 if (NULL == pstMutex) { return NULL; } #if VOS_APP_OS == VOS_OS_LINUX ulResult = (ULONG)pthread_mutex_init( &pstMutex->mutex, 0); if( VOS_OK != ulResult ) { VOS_free( pstMutex ); return VOS_NULL ; } #elif VOS_APP_OS == VOS_OS_WIN32 pstMutex->mutex = CreateMutex(NULL,0,NULL); if (NULL == pstMutex->mutex) { VOS_free( pstMutex ); return VOS_NULL ; } #endif return pstMutex ; }//lint !e529
ULONG VOS_CreateSemaphore( ULONG ulInitValue ,VOS_Sem **pstVosSem) { VOS_Sem *pstVosSemTemp = VOS_NULL ; pstVosSemTemp = (VOS_Sem *) VOS_malloc(sizeof(VOS_Sem));//lint !e838 if ( VOS_NULL == pstVosSemTemp ) { return VOS_ERR_MEM ; } #if VOS_APP_OS == VOS_OS_LINUX LONG lResult = VOS_OK ; lResult = sem_init(&pstVosSemTemp->sem, 0, ulInitValue ); if ( VOS_OK != lResult ) { VOS_free(pstVosSemTemp); return VOS_ERR_SYS ; } #elif VOS_APP_OS == VOS_OS_WIN32 pstVosSemTemp->sem = CreateSemaphore(NULL,(LONG)ulInitValue,(LONG)ulInitValue,NULL); if (NULL == pstVosSemTemp->sem) { VOS_free(pstVosSemTemp); return VOS_ERR_SYS ; } #endif *pstVosSem = pstVosSemTemp; return VOS_OK ; }//lint !e529
ULONG VOS_CreateSemaphore( ULONG ulInitValue ,VOS_Sem **pstVosSem) { VOS_Sem *pstVosSemTemp = VOS_NULL ; LONG lResult = VOS_OK ; pstVosSemTemp = (VOS_Sem *) VOS_malloc(sizeof(VOS_Sem)); if ( VOS_NULL == pstVosSemTemp ) { return VOS_ERR_MEM ; } #if VOS_APP_OS == VOS_OS_LINUX lResult = sem_init(&pstVosSemTemp->sem, 0, ulInitValue ); if ( VOS_OK != lResult ) { VOS_free(pstVosSemTemp); return VOS_ERR_SYS ; } #elif VOS_APP_OS == VOS_OS_WIN32 //pstVosSemTemp->sem = CreateSemaphore(NULL,(long)ulInitValue,(long)ulInitValue,NULL); pstVosSemTemp->sem = CreateSemaphore(NULL, (long)ulInitValue, (long)ulInitValue+1, NULL); if (NULL == pstVosSemTemp->sem) { VOS_free(pstVosSemTemp); return VOS_ERR_SYS ; } (void)lResult; #endif *pstVosSem = pstVosSemTemp; return VOS_OK ; }
ULONG VOS_CreateThread( VOS_THREAD_FUNC pfnThread, VOID *args, VOS_Thread **pstVosThread,ULONG ulStackSize) { VOS_Thread *pstThread = (VOS_Thread*)VOS_malloc(sizeof(VOS_Thread)); if( VOS_NULL == pstThread ) { return VOS_ERR_MEM; } #if VOS_APP_OS == VOS_OS_LINUX if ( pthread_attr_init(&pstThread->attr) != 0 ) { VOS_free(pstThread); return VOS_ERR ; } pthread_attr_setdetachstate(&pstThread->attr, PTHREAD_CREATE_JOINABLE ); if( 0 == ulStackSize ) { ulStackSize = VOS_DEFAULT_STACK_SIZE; } if (pthread_attr_setstacksize(&pstThread->attr, (size_t)ulStackSize)) { VOS_free(pstThread); return VOS_ERR ; } if ( pthread_create(&pstThread->pthead, &pstThread->attr, pfnThread, args) != 0 ) { VOS_free(pstThread); return VOS_ERR ; } #elif VOS_APP_OS == VOS_OS_WIN32 pstThread->pthead = CreateThread(NULL,ulStackSize,pfnThread,args,0,&pstThread->ptheadID); if (NULL == pstThread->pthead) { VOS_free(pstThread); return VOS_ERR ; } #endif *pstVosThread = pstThread ; return VOS_OK; }