本文整理汇总了C++中PR_NewCondVar函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_NewCondVar函数的具体用法?C++ PR_NewCondVar怎么用?C++ PR_NewCondVar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_NewCondVar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
nsresult
nsIOThreadPool::Init()
{
#if defined(PR_LOGGING)
if (!gIOThreadPoolLog)
gIOThreadPoolLog = PR_NewLogModule("nsIOThreadPool");
#endif
mNumThreads = 0;
mNumIdleThreads = 0;
mShutdown = PR_FALSE;
mLock = PR_NewLock();
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
mIdleThreadCV = PR_NewCondVar(mLock);
if (!mIdleThreadCV)
return NS_ERROR_OUT_OF_MEMORY;
mExitThreadCV = PR_NewCondVar(mLock);
if (!mExitThreadCV)
return NS_ERROR_OUT_OF_MEMORY;
PR_INIT_CLIST(&mEventQ);
// We want to shutdown the i/o thread pool at xpcom-shutdown-threads time.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os)
os->AddObserver(this, "xpcom-shutdown-threads", PR_FALSE);
return NS_OK;
}
示例2: launch_thread
SECStatus
launch_thread(GlobalThreadMgr *threadMGR,
startFn *startFunc,
void *a,
int b)
{
perThread *slot;
int i;
if (!threadMGR->threadStartQ) {
threadMGR->threadLock = PR_NewLock();
threadMGR->threadStartQ = PR_NewCondVar(threadMGR->threadLock);
threadMGR->threadEndQ = PR_NewCondVar(threadMGR->threadLock);
}
PR_Lock(threadMGR->threadLock);
while (threadMGR->numRunning >= MAX_THREADS) {
PR_WaitCondVar(threadMGR->threadStartQ, PR_INTERVAL_NO_TIMEOUT);
}
for (i = 0; i < threadMGR->numUsed; ++i) {
slot = &threadMGR->threads[i];
if (slot->running == rs_idle)
break;
}
if (i >= threadMGR->numUsed) {
if (i >= MAX_THREADS) {
/* something's really wrong here. */
PORT_Assert(i < MAX_THREADS);
PR_Unlock(threadMGR->threadLock);
return SECFailure;
}
++(threadMGR->numUsed);
PORT_Assert(threadMGR->numUsed == i + 1);
slot = &threadMGR->threads[i];
}
slot->a = a;
slot->b = b;
slot->startFunc = startFunc;
threadMGR->index = i;
slot->prThread = PR_CreateThread(PR_USER_THREAD,
thread_wrapper, threadMGR,
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
PR_JOINABLE_THREAD, 0);
if (slot->prThread == NULL) {
PR_Unlock(threadMGR->threadLock);
printf("Failed to launch thread!\n");
return SECFailure;
}
slot->inUse = 1;
slot->running = 1;
++(threadMGR->numRunning);
PR_Unlock(threadMGR->threadLock);
return SECSuccess;
}
示例3: alloc_threadpool
static PRThreadPool *
alloc_threadpool(void)
{
PRThreadPool *tp;
tp = (PRThreadPool *) PR_CALLOC(sizeof(*tp));
if (NULL == tp)
goto failed;
tp->jobq.lock = PR_NewLock();
if (NULL == tp->jobq.lock)
goto failed;
tp->jobq.cv = PR_NewCondVar(tp->jobq.lock);
if (NULL == tp->jobq.cv)
goto failed;
tp->join_lock = PR_NewLock();
if (NULL == tp->join_lock)
goto failed;
#ifdef OPT_WINNT
tp->jobq.nt_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
NULL, 0, 0);
if (NULL == tp->jobq.nt_completion_port)
goto failed;
#endif
tp->ioq.lock = PR_NewLock();
if (NULL == tp->ioq.lock)
goto failed;
/* Timer queue */
tp->timerq.lock = PR_NewLock();
if (NULL == tp->timerq.lock)
goto failed;
tp->timerq.cv = PR_NewCondVar(tp->timerq.lock);
if (NULL == tp->timerq.cv)
goto failed;
tp->shutdown_cv = PR_NewCondVar(tp->jobq.lock);
if (NULL == tp->shutdown_cv)
goto failed;
tp->ioq.notify_fd = PR_NewPollableEvent();
if (NULL == tp->ioq.notify_fd)
goto failed;
return tp;
failed:
delete_threadpool(tp);
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return NULL;
}
示例4: mCondVar
CondVarNSPR::CondVarNSPR(MutexNSPR* mutex)
: mCondVar(NULL)
, mCondMutex(NULL)
{
// If the caller did not specify a mutex variable to use with
// the condition variable, use mDefaultMutex.
if ( mutex == NULL )
{
mCondMutex = &mDefaultMutex;
}
else
{
mCondMutex = mutex;
}
// Initialize the condition variable.
mCondVar = PR_NewCondVar(mCondMutex->mMutex);
if ( NULL == mCondVar )
{
std::ostringstream msg_stream;
NSPR_PrintError("Condition variable allocation failed: ", msg_stream);
throw vpr::ResourceException(msg_stream.str(), VPR_LOCATION);
}
}
示例5: _PR_InitIO
void _PR_InitIO(void)
{
const PRIOMethods *methods = PR_GetFileMethods();
_PR_InitFdCache();
_pr_flock_lock = PR_NewLock();
_pr_flock_cv = PR_NewCondVar(_pr_flock_lock);
#ifdef WIN32
_pr_stdin = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_INPUT_HANDLE),
methods);
_pr_stdout = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_OUTPUT_HANDLE),
methods);
_pr_stderr = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_ERROR_HANDLE),
methods);
#ifdef WINNT
_pr_stdin->secret->md.sync_file_io = PR_TRUE;
_pr_stdout->secret->md.sync_file_io = PR_TRUE;
_pr_stderr->secret->md.sync_file_io = PR_TRUE;
#endif
#else
_pr_stdin = PR_AllocFileDesc(0, methods);
_pr_stdout = PR_AllocFileDesc(1, methods);
_pr_stderr = PR_AllocFileDesc(2, methods);
#endif
_PR_MD_INIT_FD_INHERITABLE(_pr_stdin, PR_TRUE);
_PR_MD_INIT_FD_INHERITABLE(_pr_stdout, PR_TRUE);
_PR_MD_INIT_FD_INHERITABLE(_pr_stderr, PR_TRUE);
_PR_MD_INIT_IO();
}
示例6: PR_IMPLEMENT
PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRUintn value)
{
PRSemaphore *semaphore;
static PRBool unwarned = PR_TRUE;
if (!_pr_initialized) _PR_ImplicitInitialization();
if (unwarned) unwarned = _PR_Obsolete(
"PR_NewSem", "locks & condition variables");
semaphore = PR_NEWZAP(PRSemaphore);
if (NULL != semaphore)
{
PRLock *lock = PR_NewLock();
if (NULL != lock)
{
semaphore->cvar = PR_NewCondVar(lock);
if (NULL != semaphore->cvar)
{
semaphore->count = value;
return semaphore;
}
PR_DestroyLock(lock);
}
PR_Free(semaphore);
}
return NULL;
}
示例7: ConditionTimeout
static PRIntervalTime ConditionTimeout(PRUint32 loops)
{
PRUintn count;
PRIntervalTime overhead, timein = PR_IntervalNow();
PRLock *ml = PR_NewLock();
PRCondVar *cv = PR_NewCondVar(ml);
PRIntervalTime interval = PR_MillisecondsToInterval(50);
overhead = PR_IntervalNow() - timein;
PR_Lock(ml);
for (count = 0; count < loops; ++count)
{
overhead += interval;
PR_ASSERT(PR_WaitCondVar(cv, interval) == PR_SUCCESS);
}
PR_Unlock(ml);
timein = PR_IntervalNow();
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
overhead += (PR_IntervalNow() - timein);
return overhead;
} /* ConditionTimeout */
示例8: alloc_job
static PRJob *
alloc_job(PRBool joinable, PRThreadPool *tp)
{
PRJob *jobp;
jobp = PR_NEWZAP(PRJob);
if (NULL == jobp)
goto failed;
if (joinable) {
jobp->join_cv = PR_NewCondVar(tp->join_lock);
jobp->join_wait = PR_TRUE;
if (NULL == jobp->join_cv)
goto failed;
} else {
jobp->join_cv = NULL;
}
#ifdef OPT_WINNT
jobp->nt_notifier.jobp = jobp;
#endif
return jobp;
failed:
delete_job(jobp);
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return NULL;
}
示例9: PR_NewLock
LdapSessionPool::LdapSessionPool(LdapServerSet *servers, unsigned short limit,
dyngroupmode_t dyngroupmode)
{
authmethod=NULL;
certNickName=NULL;
_maxSessions = (limit < 1 ? 1 : limit);
_dyngroupmode = dyngroupmode;
//_servers = servers;
_waiters = 0;
_lock = PR_NewLock();
assert(_lock);
_cvar = PR_NewCondVar(_lock);
assert(_cvar);
// add new pool to list of all pools
if (_poolListLock == NULL) {
static PRCallOnceType once = { 0, 0, (PRStatus)0 };
PR_CallOnce(&once, PoolListCreate);
}
PR_Lock(_poolListLock);
_nextPool = _poolList;
_poolList = this;
PR_Unlock(_poolListLock);
}
示例10: NS_ENSURE_TRUE
nsresult PeerConnectionCtx::Initialize() {
mCCM = CSF::CallControlManager::create();
NS_ENSURE_TRUE(mCCM.get(), NS_ERROR_FAILURE);
// Add the local audio codecs
// FIX - Get this list from MediaEngine instead
int codecMask = 0;
codecMask |= VCM_CODEC_RESOURCE_G711;
codecMask |= VCM_CODEC_RESOURCE_OPUS;
//codecMask |= VCM_CODEC_RESOURCE_LINEAR;
//codecMask |= VCM_CODEC_RESOURCE_G722;
//codecMask |= VCM_CODEC_RESOURCE_iLBC;
//codecMask |= VCM_CODEC_RESOURCE_iSAC;
mCCM->setAudioCodecs(codecMask);
//Add the local video codecs
// FIX - Get this list from MediaEngine instead
// Turning them all on for now
codecMask = 0;
// Only adding codecs supported
//codecMask |= VCM_CODEC_RESOURCE_H263;
//codecMask |= VCM_CODEC_RESOURCE_H264;
codecMask |= VCM_CODEC_RESOURCE_VP8;
//codecMask |= VCM_CODEC_RESOURCE_I420;
mCCM->setVideoCodecs(codecMask);
ccAppReadyToStartLock = PR_NewLock();
if (!ccAppReadyToStartLock) {
return NS_ERROR_FAILURE;
}
ccAppReadyToStartCond = PR_NewCondVar(ccAppReadyToStartLock);
if (!ccAppReadyToStartCond) {
return NS_ERROR_FAILURE;
}
if (!mCCM->startSDPMode())
return NS_ERROR_FAILURE;
mDevice = mCCM->getActiveDevice();
mCCM->addCCObserver(this);
NS_ENSURE_TRUE(mDevice.get(), NS_ERROR_FAILURE);
ChangeSipccState(mozilla::dom::PCImplSipccState::Starting);
// Now that everything is set up, we let the CCApp thread
// know that it's okay to start processing messages.
PR_Lock(ccAppReadyToStartLock);
ccAppReadyToStart = 1;
PR_NotifyAllCondVar(ccAppReadyToStartCond);
PR_Unlock(ccAppReadyToStartLock);
mConnectionCounter = 0;
#ifdef MOZILLA_INTERNAL_API
Telemetry::GetHistogramById(Telemetry::WEBRTC_CALL_COUNT)->Add(0);
#endif
return NS_OK;
}
示例11: common
void DNSSession :: common(PRIntervalTime tm)
{
starttime = PR_IntervalNow();
timeout = tm;
timedout = PR_FALSE;
sendfailed = PR_FALSE;
id = 0;
lock = PR_NewLock();
PR_ASSERT(lock);
cvar = PR_NewCondVar(lock);
PR_ASSERT(cvar);
status = DNS_INIT;
awake = PR_FALSE;
// query stuff
re_retries = _res.retry;
re_sends = 1;
re_resend = 1;
re_he.h_addr_list[0] = 0;
re_data = NULL;
re_sent = 0;
re_srch = 0;
re_type = 0;
memset(re_name, 0, sizeof(re_name));
memset((void*)&re_he, 0, sizeof(re_he));
memset((void*)&ar_host, 0, sizeof(ar_host));
}
示例12: PR_IMPLEMENT
/*
** Create a new semaphore.
*/
PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRUintn value)
{
PRSemaphore *sem;
PRCondVar *cvar;
PRLock *lock;
sem = PR_NEWZAP(PRSemaphore);
if (sem) {
#ifdef HAVE_CVAR_BUILT_ON_SEM
_PR_MD_NEW_SEM(&sem->md, value);
#else
lock = PR_NewLock();
if (!lock) {
PR_DELETE(sem);
return NULL;
}
cvar = PR_NewCondVar(lock);
if (!cvar) {
PR_DestroyLock(lock);
PR_DELETE(sem);
return NULL;
}
sem->cvar = cvar;
sem->count = value;
#endif
}
return sem;
}
示例13: forked
static void PR_CALLBACK forked(void *arg)
{
PRIntn i;
PRLock *ml;
PRCondVar *cv;
PR_LogPrint("%s logging creating mutex\n", (const char*)arg);
ml = PR_NewLock();
PR_LogPrint("%s logging creating condition variable\n", (const char*)arg);
cv = PR_NewCondVar(ml);
PR_LogPrint("%s waiting on condition timeout 10 times\n", (const char*)arg);
for (i = 0; i < 10; ++i)
{
PR_Lock(ml);
PR_WaitCondVar(cv, PR_SecondsToInterval(1));
PR_Unlock(ml);
}
PR_LogPrint("%s logging destroying condition variable\n", (const char*)arg);
PR_DestroyCondVar(cv);
PR_LogPrint("%s logging destroying mutex\n", (const char*)arg);
PR_DestroyLock(ml);
PR_LogPrint("%s forked thread exiting\n", (const char*)arg);
}
示例14: PR_IMPLEMENT
/*
** Create a new monitor.
*/
PR_IMPLEMENT(PRMonitor*) PR_NewMonitor()
{
PRMonitor *mon;
PRCondVar *cvar;
PRLock *lock;
mon = PR_NEWZAP(PRMonitor);
if (mon) {
lock = PR_NewLock();
if (!lock) {
PR_DELETE(mon);
return 0;
}
cvar = PR_NewCondVar(lock);
if (!cvar) {
PR_DestroyLock(lock);
PR_DELETE(mon);
return 0;
}
mon->cvar = cvar;
mon->name = NULL;
}
return mon;
}
示例15: TestIntervals
static void TestIntervals(void)
{
PRStatus rv;
PRUint32 delta;
PRInt32 seconds;
PRUint64 elapsed, thousand;
PRTime timein, timeout;
PRLock *ml = PR_NewLock();
PRCondVar *cv = PR_NewCondVar(ml);
for (seconds = 0; seconds < 10; ++seconds)
{
PRIntervalTime ticks = PR_SecondsToInterval(seconds);
PR_Lock(ml);
timein = PR_Now();
rv = PR_WaitCondVar(cv, ticks);
timeout = PR_Now();
PR_Unlock(ml);
LL_SUB(elapsed, timeout, timein);
LL_I2L(thousand, 1000);
LL_DIV(elapsed, elapsed, thousand);
LL_L2UI(delta, elapsed);
if (debug_mode) PR_fprintf(output,
"TestIntervals: %swaiting %ld seconds took %ld msecs\n",
((rv == PR_SUCCESS) ? "" : "FAILED "), seconds, delta);
}
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
if (debug_mode) PR_fprintf(output, "\n");
} /* TestIntervals */