本文整理汇总了C++中PR_NewLock函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_NewLock函数的具体用法?C++ PR_NewLock怎么用?C++ PR_NewLock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_NewLock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
nsresult
nsConsoleService::Init()
{
mMessages = (nsIConsoleMessage **)
nsMemory::Alloc(mBufferSize * sizeof(nsIConsoleMessage *));
if (!mMessages)
return NS_ERROR_OUT_OF_MEMORY;
// Array elements should be 0 initially for circular buffer algorithm.
memset(mMessages, 0, mBufferSize * sizeof(nsIConsoleMessage *));
mLock = PR_NewLock();
if (!mLock)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
示例2: prmain
static PRIntn prmain(PRIntn argc, char **argv)
{
PRStatus rv;
PRLock *ml = PR_NewLock();
PRCondVar *cv = PRP_NewNakedCondVar();
PRIntervalTime tenmsecs = PR_MillisecondsToInterval(10);
rv = PRP_TryLock(ml);
PR_ASSERT(PR_SUCCESS == rv);
if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
rv = PRP_TryLock(ml);
PR_ASSERT(PR_FAILURE == rv);
if ((rv != PR_FAILURE) & (!debug_mode)) failed_already=1;
rv = PRP_NakedNotify(cv);
PR_ASSERT(PR_SUCCESS == rv);
if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
rv = PRP_NakedBroadcast(cv);
PR_ASSERT(PR_SUCCESS == rv);
if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
rv = PRP_NakedWait(cv, ml, tenmsecs);
PR_ASSERT(PR_SUCCESS == rv);
if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
PR_Unlock(ml);
rv = PRP_NakedNotify(cv);
PR_ASSERT(PR_SUCCESS == rv);
if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
rv = PRP_NakedBroadcast(cv);
PR_ASSERT(PR_SUCCESS == rv);
if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
PRP_DestroyNakedCondVar(cv);
PR_DestroyLock(ml);
if (debug_mode) printf("Test succeeded\n");
return 0;
} /* prmain */
示例3: PR_NewLock
/* new searchthread */
SearchThread *st_new(void)
{
SearchThread *st = (SearchThread *)malloc(sizeof(SearchThread));
if (!st) return NULL;
st->searchCount = st->failCount = 0;
st->mintime = 10000;
st->maxtime = 0;
st->ld = NULL;
st->ld2 = NULL;
st->soc = -1;
st->tid = NULL;
st->id = 0;
st->alive = 1;
st->lock = PR_NewLock();
st->retry = 0;
return st;
}
示例4: Pk11Install_SetErrorHandler
/**************************************************************************
*
* P k 1 1 I n s t a l l _ S e t E r r o r H a n d l e r
*
* Sets the error handler to be used by the library. Returns the current
* error handler function.
*/
Pk11Install_ErrorHandler
Pk11Install_SetErrorHandler(Pk11Install_ErrorHandler handler)
{
Pk11Install_ErrorHandler old;
if (!errorHandlerLock) {
errorHandlerLock = PR_NewLock();
}
PR_Lock(errorHandlerLock);
old = errorHandler;
errorHandler = handler;
PR_Unlock(errorHandlerLock);
return old;
}
示例5: objset_new
/*
* Create a new, empty object set.
* Returns a pointer to the new object set, or NULL if an error occurred.
*/
Objset *
objset_new(FNFree objset_destructor)
{
objset *set;
set = (objset *)slapi_ch_malloc(sizeof(objset));
set->lock = PR_NewLock();
if (NULL == set->lock)
{
slapi_ch_free((void **)&set);
}
else
{
set->head = set->tail = NULL;
set->destructor = objset_destructor;
}
return set;
}
示例6: create_counters
static void
create_counters()
{
PR_CREATE_COUNTER(slapi_ch_counter_malloc,"slapi_ch","malloc","");
PR_CREATE_COUNTER(slapi_ch_counter_calloc,"slapi_ch","calloc","");
PR_CREATE_COUNTER(slapi_ch_counter_realloc,"slapi_ch","realloc","");
PR_CREATE_COUNTER(slapi_ch_counter_strdup,"slapi_ch","strdup","");
PR_CREATE_COUNTER(slapi_ch_counter_free,"slapi_ch","free","");
PR_CREATE_COUNTER(slapi_ch_counter_created,"slapi_ch","created","");
PR_CREATE_COUNTER(slapi_ch_counter_exist,"slapi_ch","exist","");
/* ensure that we have space to allow for shutdown calls to malloc()
* from should we run out of memory.
*/
if (oom_emergency_area == NULL) {
oom_emergency_area = malloc(OOM_PREALLOC_SIZE);
}
oom_emergency_lock = PR_NewLock();
}
示例7: _PR_InitFdCache
void _PR_InitFdCache(void)
{
/*
** The fd caching is enabled by default for DEBUG builds,
** disabled by default for OPT builds. That default can
** be overridden at runtime using environment variables
** or a super-wiz-bang API.
*/
const char *low = PR_GetEnv("NSPR_FD_CACHE_SIZE_LOW");
const char *high = PR_GetEnv("NSPR_FD_CACHE_SIZE_HIGH");
/*
** _low is allowed to be zero, _high is not.
** If _high is zero, we're not doing the caching.
*/
_pr_fd_cache.limit_low = 0;
#if defined(DEBUG)
_pr_fd_cache.limit_high = FD_SETSIZE;
#else
_pr_fd_cache.limit_high = 0;
#endif /* defined(DEBUG) */
if (NULL != low) _pr_fd_cache.limit_low = atoi(low);
if (NULL != high) _pr_fd_cache.limit_high = atoi(high);
if (_pr_fd_cache.limit_low < 0)
_pr_fd_cache.limit_low = 0;
if (_pr_fd_cache.limit_low > FD_SETSIZE)
_pr_fd_cache.limit_low = FD_SETSIZE;
if (_pr_fd_cache.limit_high > FD_SETSIZE)
_pr_fd_cache.limit_high = FD_SETSIZE;
if (_pr_fd_cache.limit_high < _pr_fd_cache.limit_low)
_pr_fd_cache.limit_high = _pr_fd_cache.limit_low;
_pr_fd_cache.ml = PR_NewLock();
PR_ASSERT(NULL != _pr_fd_cache.ml);
_pr_fd_cache.stack = PR_CreateStack("FD");
PR_ASSERT(NULL != _pr_fd_cache.stack);
} /* _PR_InitFdCache */
示例8: PR_NewLock
/* new addthread */
AddThread *at_new(void)
{
AddThread *at = (AddThread *)malloc(sizeof(AddThread));
if (!at) return NULL;
at->addCount = at->failCount = at->addTotal = 0;
at->mintime = 10000;
at->maxtime = 0;
at->ld = NULL;
at->tid = NULL;
at->id = 0;
at->alive = 1;
at->retry = 0;
at->lock = PR_NewLock();
at->blob = NULL;
/* make sure the id generator has initialized */
getID();
return at;
}
示例9: jsd_CreateLock
void*
jsd_CreateLock()
{
JSDStaticLock* lock;
if( ! (lock = (JSDStaticLock*)calloc(1, sizeof(JSDStaticLock))) ||
! (lock->lock = PR_NewLock()) )
{
if(lock)
{
free(lock);
lock = NULL;
}
}
#ifdef DEBUG
if(lock) lock->sig = (uint16) JSD_LOCK_SIG;
#endif
return lock;
}
示例10: RealMain
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "dhlmc");
PRBool locks = PR_FALSE, monitors = PR_FALSE, cmonitors = PR_FALSE;
err = PR_GetSpecialFD(PR_StandardError);
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
if (PL_OPT_BAD == os) continue;
switch (opt->option)
{
case 'd': /* debug mode (noop) */
break;
case 'l': /* locks */
locks = PR_TRUE;
break;
case 'm': /* monitors */
monitors = PR_TRUE;
break;
case 'c': /* cached monitors */
cmonitors = PR_TRUE;
break;
case 'h': /* needs guidance */
default:
Help();
return 2;
}
}
PL_DestroyOptState(opt);
ml = PR_NewLock();
if (locks) T1Lock();
if (monitors) T1Mon();
if (cmonitors) T1CMon();
PR_DestroyLock(ml);
PR_fprintf(err, "Done!\n");
return 0;
} /* main */
示例11: TimerInit
static PRStatus TimerInit(void)
{
tm_vars.ml = PR_NewLock();
if (NULL == tm_vars.ml)
{
goto failed;
}
tm_vars.new_timer = PR_NewCondVar(tm_vars.ml);
if (NULL == tm_vars.new_timer)
{
goto failed;
}
tm_vars.cancel_timer = PR_NewCondVar(tm_vars.ml);
if (NULL == tm_vars.cancel_timer)
{
goto failed;
}
PR_INIT_CLIST(&tm_vars.timer_queue);
tm_vars.manager_thread = PR_CreateThread(
PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
if (NULL == tm_vars.manager_thread)
{
goto failed;
}
return PR_SUCCESS;
failed:
if (NULL != tm_vars.cancel_timer)
{
PR_DestroyCondVar(tm_vars.cancel_timer);
}
if (NULL != tm_vars.new_timer)
{
PR_DestroyCondVar(tm_vars.new_timer);
}
if (NULL != tm_vars.ml)
{
PR_DestroyLock(tm_vars.ml);
}
return PR_FAILURE;
}
示例12: ContentiousLock
static PRIntervalTime ContentiousLock(PRUint32 loops)
{
PRStatus status;
PRThread *thread = NULL;
LockContentious_t * contention;
PRIntervalTime rv, overhead, timein = PR_IntervalNow();
contention = PR_NEWZAP(LockContentious_t);
contention->loops = loops;
contention->overhead = 0;
contention->ml = PR_NewLock();
contention->interval = contention_interval;
thread = PR_CreateThread(
PR_USER_THREAD, LockContender, contention,
PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
while (contention->loops-- > 0)
{
PR_Lock(contention->ml);
PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(contention->ml);
contention->contentious+= 1;
contention->overhead += contention->interval;
PR_Sleep(contention->interval);
PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(contention->ml);
PR_Unlock(contention->ml);
}
timein = PR_IntervalNow();
status = PR_JoinThread(thread);
PR_DestroyLock(contention->ml);
overhead += (PR_IntervalNow() - timein);
rv = overhead + contention->overhead;
if (verbosity)
PR_fprintf(
std_err, "Access ratio: %u to %u\n",
contention->contentious, contention->contender);
PR_Free(contention);
return rv;
} /* ContentiousLock */
示例13: PR_NewLock
LdapSessionPool::LdapSessionPool(LdapRealm *ldapRealm,int limit)
{
_ldapRealm = ldapRealm;
_maxSessions = (limit < 1 ? 1 : limit);
_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);
}
示例14: mThread
nsSocketTransportService::nsSocketTransportService()
: mThread(nsnull)
, mThreadEvent(nsnull)
, mAutodialEnabled(PR_FALSE)
, mLock(PR_NewLock())
, mInitialized(PR_FALSE)
, mShuttingDown(PR_FALSE)
, mActiveCount(0)
, mIdleCount(0)
, mSendBufferSize(0)
{
#if defined(PR_LOGGING)
gSocketTransportLog = PR_NewLogModule("nsSocketTransport");
#endif
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
NS_ASSERTION(!gSocketTransportService, "must not instantiate twice");
gSocketTransportService = this;
}
示例15: m_pLock
//-----------------------------------------------------------------------------
CDatabaseQuery::CDatabaseQuery()
: m_pLock(PR_NewLock())
, m_IsAborting(PR_FALSE)
, m_IsExecuting(PR_FALSE)
, m_AsyncQuery(PR_FALSE)
, m_CurrentQuery((PRUint32)-1)
, m_LastError(0)
, m_pQueryRunningMonitor(nsAutoMonitor::NewMonitor("CDatabaseQuery.m_pdbQueryRunningMonitor"))
, m_QueryHasCompleted(PR_FALSE)
, m_RollingLimit(0)
, m_RollingLimitColumnIndex(0)
, m_RollingLimitResult(0)
{
#ifdef PR_LOGGING
if (!sDatabaseQueryLog)
sDatabaseQueryLog = PR_NewLogModule("sbDatabaseQuery");
#endif
m_CallbackList.Init(DATABASEQUERY_DEFAULT_CALLBACK_SLOTS);
} //ctor