本文整理汇总了C++中PR_NEWZAP函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_NEWZAP函数的具体用法?C++ PR_NEWZAP怎么用?C++ PR_NEWZAP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_NEWZAP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PR_CreateThreadPool
PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads,
PRUint32 stacksize)
{
PRThreadPool *tp;
PRThread *thr;
int i;
wthread *wthrp;
tp = alloc_threadpool();
if (NULL == tp)
return NULL;
tp->init_threads = initial_threads;
tp->max_threads = max_threads;
tp->stacksize = stacksize;
PR_INIT_CLIST(&tp->jobq.list);
PR_INIT_CLIST(&tp->ioq.list);
PR_INIT_CLIST(&tp->timerq.list);
PR_INIT_CLIST(&tp->jobq.wthreads);
PR_INIT_CLIST(&tp->ioq.wthreads);
PR_INIT_CLIST(&tp->timerq.wthreads);
tp->shutdown = PR_FALSE;
PR_Lock(tp->jobq.lock);
for(i=0; i < initial_threads; ++i) {
thr = PR_CreateThread(PR_USER_THREAD, wstart,
tp, PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD, PR_JOINABLE_THREAD,stacksize);
PR_ASSERT(thr);
wthrp = PR_NEWZAP(wthread);
PR_ASSERT(wthrp);
wthrp->thread = thr;
PR_APPEND_LINK(&wthrp->links, &tp->jobq.wthreads);
}
tp->current_threads = initial_threads;
thr = PR_CreateThread(PR_USER_THREAD, io_wstart,
tp, PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,stacksize);
PR_ASSERT(thr);
wthrp = PR_NEWZAP(wthread);
PR_ASSERT(wthrp);
wthrp->thread = thr;
PR_APPEND_LINK(&wthrp->links, &tp->ioq.wthreads);
thr = PR_CreateThread(PR_USER_THREAD, timer_wstart,
tp, PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,stacksize);
PR_ASSERT(thr);
wthrp = PR_NEWZAP(wthread);
PR_ASSERT(wthrp);
wthrp->thread = thr;
PR_APPEND_LINK(&wthrp->links, &tp->timerq.wthreads);
PR_Unlock(tp->jobq.lock);
return tp;
}
示例2: PR_IMPLEMENT
/*
** Create a new condition variable.
** "lock" is the lock to use with the condition variable.
**
** Condition variables are synchronization objects that threads can use
** to wait for some condition to occur.
**
** This may fail if memory is tight or if some operating system resource
** is low.
*/
PR_IMPLEMENT(PRCondVar*) PR_NewCondVar(PRLock *lock)
{
PRCondVar *cvar;
PR_ASSERT(lock != NULL);
cvar = PR_NEWZAP(PRCondVar);
if (cvar) {
#ifdef _PR_GLOBAL_THREADS_ONLY
if(_PR_MD_NEW_CV(&cvar->md)) {
PR_DELETE(cvar);
PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
return NULL;
}
#endif
if (_PR_MD_NEW_LOCK(&(cvar->ilock)) == PR_FAILURE) {
PR_DELETE(cvar);
PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
return NULL;
}
cvar->lock = lock;
PR_INIT_CLIST(&cvar->condQ);
} else {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
}
return cvar;
}
示例3: md_PostNotifyToCvar
/*
* Notifies just get posted to the protecting mutex. The
* actual notification is done when the lock is released so that
* MP systems don't contend for a lock that they can't have.
*/
static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
PRBool broadcast)
{
PRIntn index = 0;
_MDNotified *notified = &lock->notified;
while (1) {
for (index = 0; index < notified->length; ++index) {
if (notified->cv[index].cv == cvar) {
if (broadcast) {
notified->cv[index].times = -1;
} else if (-1 != notified->cv[index].times) {
notified->cv[index].times += 1;
}
return;
}
}
/* if not full, enter new CV in this array */
if (notified->length < _MD_CV_NOTIFIED_LENGTH) break;
/* if there's no link, create an empty array and link it */
if (NULL == notified->link) {
notified->link = PR_NEWZAP(_MDNotified);
}
notified = notified->link;
}
/* A brand new entry in the array */
notified->cv[index].times = (broadcast) ? -1 : 1;
notified->cv[index].cv = cvar;
notified->length += 1;
}
示例4: PR_IMPLEMENT
PR_IMPLEMENT(PRAlarmID*) PR_SetAlarm(
PRAlarm *alarm, PRIntervalTime period, PRUint32 rate,
PRPeriodicAlarmFn function, void *clientData)
{
/*
* Create a new periodic alarm an existing current structure.
* Set up the context and compute the first notify time (immediate).
* Link the new ID into the head of the list (since it's notifying
* immediately).
*/
PRAlarmID *id = PR_NEWZAP(PRAlarmID);
if (!id)
return NULL;
id->alarm = alarm;
PR_INIT_CLIST(&id->list);
id->function = function;
id->clientData = clientData;
id->period = period;
id->rate = rate;
id->epoch = id->nextNotify = PR_IntervalNow();
(void)pr_PredictNextNotifyTime(id);
PR_Lock(alarm->lock);
PR_INSERT_BEFORE(&id->list, &alarm->timers);
PR_NotifyCondVar(alarm->cond);
PR_Unlock(alarm->lock);
return id;
} /* PR_SetAlarm */
示例5: 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;
}
示例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: 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;
}
示例8: 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;
}
示例9: PR_CreateIOLayerStub
static PRFileDesc *PushLayer(PRFileDesc *stack)
{
PRStatus rv;
PRFileDesc *layer = PR_CreateIOLayerStub(identity, &myMethods);
layer->secret = PR_NEWZAP(PRFilePrivate);
rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), layer);
PR_ASSERT(PR_SUCCESS == rv);
if (verbosity > quiet)
PR_fprintf(logFile, "Pushed layer(0x%x) onto stack(0x%x)\n", layer, stack);
return stack;
} /* PushLayer */
示例10: PR_IMPLEMENT
PR_IMPLEMENT(PRMWaitEnumerator*) PR_CreateMWaitEnumerator(PRWaitGroup *group)
{
PRMWaitEnumerator *enumerator = PR_NEWZAP(PRMWaitEnumerator);
if (NULL == enumerator) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
else
{
enumerator->group = group;
enumerator->seal = _PR_ENUM_SEALED;
}
return enumerator;
} /* PR_CreateMWaitEnumerator */
示例11: add_to_jobq
/*
* add a job to the work queue
*/
static void
add_to_jobq(PRThreadPool *tp, PRJob *jobp)
{
/*
* add to jobq
*/
#ifdef OPT_WINNT
PR_Lock(tp->jobq.lock);
tp->jobq.cnt++;
PR_Unlock(tp->jobq.lock);
/*
* notify worker thread(s)
*/
PostQueuedCompletionStatus(tp->jobq.nt_completion_port, 0,
FALSE, &jobp->nt_notifier.overlapped);
#else
PR_Lock(tp->jobq.lock);
PR_APPEND_LINK(&jobp->links,&tp->jobq.list);
tp->jobq.cnt++;
if ((tp->idle_threads < tp->jobq.cnt) &&
(tp->current_threads < tp->max_threads)) {
wthread *wthrp;
/*
* increment thread count and unlock the jobq lock
*/
tp->current_threads++;
PR_Unlock(tp->jobq.lock);
/* create new worker thread */
wthrp = PR_NEWZAP(wthread);
if (wthrp) {
wthrp->thread = PR_CreateThread(PR_USER_THREAD, wstart,
tp, PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,tp->stacksize);
if (NULL == wthrp->thread) {
PR_DELETE(wthrp); /* this sets wthrp to NULL */
}
}
PR_Lock(tp->jobq.lock);
if (NULL == wthrp) {
tp->current_threads--;
} else {
PR_APPEND_LINK(&wthrp->links, &tp->jobq.wthreads);
}
}
/*
* wakeup a worker thread
*/
PR_NotifyCondVar(tp->jobq.cv);
PR_Unlock(tp->jobq.lock);
#endif
}
示例12: PR_NEWZAP
SECCipherFind *sec_CipherFindInit(PRBool onlyAllowed,
secCPStruct *policy,
long *ciphers)
{
SECCipherFind *find = PR_NEWZAP(SECCipherFind);
if (find)
{
find->policy = policy;
find->ciphers = ciphers;
find->onlyAllowed = onlyAllowed;
find->index = -1;
}
return find;
}
示例13: PR_IMPLEMENT
PR_IMPLEMENT(PRMonitor*) PR_NewMonitor(void)
{
PRMonitor *mon;
PRCondVar *cvar;
if (!_pr_initialized) _PR_ImplicitInitialization();
cvar = PR_NEWZAP(PRCondVar);
if (NULL == cvar)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return NULL;
}
mon = PR_NEWZAP(PRMonitor);
if (mon != NULL)
{
int rv;
rv = _PT_PTHREAD_MUTEX_INIT(mon->lock.mutex, _pt_mattr);
PR_ASSERT(0 == rv);
_PT_PTHREAD_INVALIDATE_THR_HANDLE(mon->owner);
mon->cvar = cvar;
rv = _PT_PTHREAD_COND_INIT(mon->cvar->cv, _pt_cvar_attr);
PR_ASSERT(0 == rv);
mon->entryCount = 0;
mon->cvar->lock = &mon->lock;
if (0 != rv)
{
PR_DELETE(mon);
PR_DELETE(cvar);
mon = NULL;
}
}
return mon;
} /* PR_NewMonitor */
示例14: PR_IMPLEMENT
PR_IMPLEMENT(PRLock*) PR_NewLock(void)
{
PRLock *lock;
if (!_pr_initialized) _PR_ImplicitInitialization();
lock = PR_NEWZAP(PRLock);
if (lock) {
if (_PR_InitLock(lock) != PR_SUCCESS) {
PR_DELETE(lock);
return NULL;
}
}
return lock;
}
示例15: PR_NewSem
PR_NewSem (PRUintn value)
{
PRSemaphore *semaphore;
if (!_pr_initialized) _PR_ImplicitInitialization();
semaphore = PR_NEWZAP(PRSemaphore);
if (NULL != semaphore) {
if ((semaphore->sem = create_sem(value, "nspr_sem")) < B_NO_ERROR)
return NULL;
else
return semaphore;
}
return NULL;
}