SECStatus sslMutex_2LevelInit(sslMutex *sem) { PR_ASSERT(sem); if (sem) { sem->u.sslLock = NULL; } return single_process_sslMutex_Init(sem); }
SECStatus sslMutex_Init(sslMutex *pMutex, int shared) { PR_ASSERT(pMutex); pMutex->isMultiProcess = (PRBool)(shared != 0); if (!shared) { return single_process_sslMutex_Init(pMutex); } PORT_Assert(!("sslMutex_Init not implemented for multi-process applications !")); PORT_SetError(PR_NOT_IMPLEMENTED_ERROR); return SECFailure; }
SECStatus sslMutex_2LevelInit(sslMutex *sem) { /* the following adds a PRLock to sslMutex . This is done in each process of a multi-process server and is only needed on WINNT, if using fibers. We can't tell if native threads or fibers are used, so we always do it on WINNT */ PR_ASSERT(sem); if (sem) { /* we need to reset the sslLock in the children or the single_process init function below will assert */ sem->u.sslLock = NULL; } return single_process_sslMutex_Init(sem); }
SECStatus sslMutex_Init(sslMutex *pMutex, int shared) { int rv; PR_ASSERT(pMutex); pMutex->isMultiProcess = (PRBool)(shared != 0); if (!shared) { return single_process_sslMutex_Init(pMutex); } do { rv = sem_init(&pMutex->u.sem, shared, 1); } while (rv < 0 && errno == EINTR); if (rv < 0) { nss_MD_unix_map_default_error(errno); return SECFailure; } return SECSuccess; }
SECStatus sslMutex_Init(sslMutex *pMutex, int shared) { #ifdef WINNT SECStatus retvalue; #endif HANDLE hMutex; SECURITY_ATTRIBUTES attributes = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; PR_ASSERT(pMutex != 0 && (pMutex->u.sslMutx == 0 || pMutex->u.sslMutx == INVALID_HANDLE_VALUE)); pMutex->isMultiProcess = (PRBool)(shared != 0); if (PR_FALSE == pMutex->isMultiProcess) { return single_process_sslMutex_Init(pMutex); } #ifdef WINNT /* we need a lock on WINNT for fibers in the parent process */ retvalue = sslMutex_2LevelInit(pMutex); if (SECSuccess != retvalue) return SECFailure; #endif if (!pMutex || ((hMutex = pMutex->u.sslMutx) != 0 && hMutex != INVALID_HANDLE_VALUE)) { PORT_SetError(PR_INVALID_ARGUMENT_ERROR); return SECFailure; } attributes.bInheritHandle = (shared ? TRUE : FALSE); hMutex = CreateMutex(&attributes, FALSE, NULL); if (hMutex == NULL) { hMutex = INVALID_HANDLE_VALUE; nss_MD_win32_map_default_error(GetLastError()); return SECFailure; } pMutex->u.sslMutx = hMutex; return SECSuccess; }
SECStatus sslMutex_Init(sslMutex *pMutex, int shared) { int err; PR_ASSERT(pMutex); pMutex->isMultiProcess = (PRBool)(shared != 0); if (!shared) { return single_process_sslMutex_Init(pMutex); } pMutex->u.pipeStr.mPipes[0] = -1; pMutex->u.pipeStr.mPipes[1] = -1; pMutex->u.pipeStr.mPipes[2] = -1; pMutex->u.pipeStr.nWaiters = 0; err = pipe(pMutex->u.pipeStr.mPipes); if (err) { nss_MD_unix_map_default_error(errno); return err; } #if NONBLOCKING_POSTS err = setNonBlocking(pMutex->u.pipeStr.mPipes[1], 1); if (err) goto loser; #endif pMutex->u.pipeStr.mPipes[2] = SSL_MUTEX_MAGIC; #if defined(LINUX) && defined(i386) /* Pipe starts out empty */ return SECSuccess; #else /* Pipe starts with one byte. */ return sslMutex_Unlock(pMutex); #endif loser: nss_MD_unix_map_default_error(errno); close(pMutex->u.pipeStr.mPipes[0]); close(pMutex->u.pipeStr.mPipes[1]); return SECFailure; }