int RLckInitLockers(void) { /* Create resource locking mutex */ if ((hRLMutex = SysCreateMutex()) == SYS_INVALID_MUTEX) return ErrGetErrorCode(); /* Initialize wait gates */ for (int i = 0; i < STD_WAIT_GATES; i++) { if ((RLGates[i].hSemaphore = SysCreateSemaphore(0, SYS_DEFAULT_MAXCOUNT)) == SYS_INVALID_SEMAPHORE) { ErrorPush(); for (--i; i >= 0; i--) { SysFree(RLGates[i].pResList); SysCloseSemaphore(RLGates[i].hSemaphore); } SysCloseMutex(hRLMutex); return ErrorPop(); } RLGates[i].iWaitingProcesses = 0; RLGates[i].iHashSize = STD_RES_HASH_SIZE; if ((RLGates[i].pResList = (SysListHead *) SysAlloc(RLGates[i].iHashSize * sizeof(SysListHead))) == NULL) { ErrorPush(); SysCloseSemaphore(RLGates[i].hSemaphore); for (--i; i >= 0; i--) { SysFree(RLGates[i].pResList); SysCloseSemaphore(RLGates[i].hSemaphore); } SysCloseMutex(hRLMutex); return ErrorPop(); } for (int j = 0; j < RLGates[i].iHashSize; j++) SYS_INIT_LIST_HEAD(&RLGates[i].pResList[j]); } return 0; }
int BSslInit(void) { int i, iNumLocks = CRYPTO_num_locks(); if ((pSslMtxs = (SYS_MUTEX *) SysAlloc(iNumLocks * sizeof(SYS_MUTEX))) == NULL) return ErrGetErrorCode(); for (i = 0; i < iNumLocks; i++) { if ((pSslMtxs[i] = SysCreateMutex()) == SYS_INVALID_MUTEX) { ErrorPush(); for (i--; i >= 0; i--) SysCloseMutex(pSslMtxs[i]); SysFreeNullify(pSslMtxs); return ErrorPop(); } } SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); CRYPTO_set_id_callback(SysGetCurrentThreadId); CRYPTO_set_locking_callback(BSslLockingCB); SysAddThreadExitHook(BSslThreadExit, NULL); return 0; }