本文整理汇总了C++中PR_Lock函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_Lock函数的具体用法?C++ PR_Lock怎么用?C++ PR_Lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_Lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NS_ENSURE_ARG
NS_IMETHODIMP nsProtectedAuthThread::Login(nsIObserver *aObserver)
{
NS_ENSURE_ARG(aObserver);
if (!mMutex)
return NS_ERROR_FAILURE;
if (!mSlot)
// We need pointer to the slot
return NS_ERROR_FAILURE;
nsCOMPtr<nsIObserver> observerProxy;
nsresult rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
NS_GET_IID(nsIObserver),
aObserver,
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
getter_AddRefs(observerProxy));
if (NS_FAILED(rv))
return rv;
PR_Lock(mMutex);
if (mIAmRunning || mLoginReady) {
PR_Unlock(mMutex);
return NS_OK;
}
observerProxy.swap(mStatusObserver);
mIAmRunning = PR_TRUE;
mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsProtectedAuthThreadRunner, static_cast<void*>(this),
PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
// bool thread_started_ok = (threadHandle != nsnull);
// we might want to return "thread started ok" to caller in the future
NS_ASSERTION(mThreadHandle, "Could not create nsProtectedAuthThreadRunner thread\n");
PR_Unlock(mMutex);
return NS_OK;
}
示例2: pagedresults_reset_processing
/*
* mark the connection as being done with pagedresults
* processing - returns True if it was processing,
* False otherwise
*/
int
pagedresults_reset_processing(Connection *conn, int index)
{
int ret = 0;
LDAPDebug1Arg(LDAP_DEBUG_TRACE,
"--> pagedresults_reset_processing: idx=%d\n", index);
if (conn && (index > -1)) {
PR_Lock(conn->c_mutex);
if (index < conn->c_pagedresults.prl_maxlen) {
ret = (conn->c_pagedresults.prl_list[index].pr_flags &
CONN_FLAG_PAGEDRESULTS_PROCESSING);
/* if ret is false, the following doesn't do anything */
conn->c_pagedresults.prl_list[index].pr_flags &=
~CONN_FLAG_PAGEDRESULTS_PROCESSING;
}
PR_Unlock(conn->c_mutex);
}
LDAPDebug1Arg(LDAP_DEBUG_TRACE,
"<-- pagedresults_reset_processing: %d\n", ret);
return ret;
}
示例3: pagedresults_set_search_result_set_size_estimate
int
pagedresults_set_search_result_set_size_estimate(Connection *conn,
int count, int index)
{
int rc = -1;
LDAPDebug1Arg(LDAP_DEBUG_TRACE,
"--> pagedresults_set_search_result_set_size_estimate: "
"idx=%d\n", index);
if (conn && (index > -1)) {
PR_Lock(conn->c_mutex);
if (index < conn->c_pagedresults.prl_maxlen) {
conn->c_pagedresults.prl_list[index].pr_search_result_set_size_estimate = count;
}
PR_Unlock(conn->c_mutex);
rc = 0;
}
LDAPDebug1Arg(LDAP_DEBUG_TRACE,
"<-- pagedresults_set_search_result_set_size_estimate: %d\n",
rc);
return rc;
}
示例4: at_getCountMinMax
/* fetches the current min/max times and the search count, and clears them */
void at_getCountMinMax(AddThread *at, PRUint32 *count, PRUint32 *min,
PRUint32 *max, PRUint32 *total)
{
PR_Lock(at->lock);
if (count) {
*count = at->addCount;
at->addCount = 0;
}
if (min) {
*min = at->mintime;
at->mintime = 10000;
}
if (max) {
*max = at->maxtime;
at->maxtime = 0;
}
if (total)
*total = at->addTotal;
at->alive--;
PR_Unlock(at->lock);
}
示例5: slapi_eq_get_arg
/*
* return arg (ec_arg) only if the context is in the event queue
*/
void *
slapi_eq_get_arg ( Slapi_Eq_Context ctx )
{
slapi_eq_context **p;
PR_ASSERT(eq_initialized);
if (!eq_stopped) {
PR_Lock(eq->eq_lock);
p = &(eq->eq_queue);
while (p && *p != NULL) {
if ((*p)->ec_id == ctx) {
PR_Unlock(eq->eq_lock);
return (*p)->ec_arg;
} else {
p = &((*p)->ec_next);
}
}
PR_Unlock(eq->eq_lock);
}
return NULL;
}
示例6: objset_first_obj
/*
* Prepare for iteration across an object set. Returns the first
* object in the set. The returned object is referenced, therefore
* the caller must either release the object, or
* pass it to an objset_next_obj call, which will
* implicitly release the object.
* Returns the first object, or NULL if the objset contains no
* objects.
*/
Object *
objset_first_obj(Objset *set)
{
Object *return_object;
/* Be tolerant (for the replication plugin) */
if (set == NULL) return NULL;
PR_Lock(set->lock);
if (NULL == set->head)
{
return_object = NULL;
}
else
{
object_acquire(set->head->obj);
return_object = set->head->obj;
}
PR_Unlock(set->lock);
return return_object;
}
示例7: MOZ_ASSERT
/* static */ bool
DiscardTracker::TryAllocation(uint64_t aBytes)
{
MOZ_ASSERT(sInitialized);
PR_Lock(sAllocationLock);
bool enoughSpace =
!gfxPrefs::ImageMemHardLimitDecodedImageKB() ||
(gfxPrefs::ImageMemHardLimitDecodedImageKB() * 1024) - sCurrentDecodedImageBytes >= aBytes;
if (enoughSpace) {
sCurrentDecodedImageBytes += aBytes;
}
PR_Unlock(sAllocationLock);
// If we're using too much memory for decoded images, MaybeDiscardSoon will
// enqueue a callback to discard some images.
MaybeDiscardSoon();
return enoughSpace;
}
示例8: ldbm_back_rmdb
int
ldbm_back_rmdb( Slapi_PBlock *pb )
{
struct ldbminfo *li = NULL;
/* char *directory = NULL;*/
int return_value = -1;
Slapi_Backend *be;
slapi_pblock_get( pb, SLAPI_BACKEND, &be );
if (be->be_state != BE_STATE_STOPPED)
{
LDAPDebug( LDAP_DEBUG_TRACE,
"ldbm_back_cleanup: warning - backend is in a wrong state - %d\n",
be->be_state, 0, 0 );
return 0;
}
PR_Lock (be->be_state_lock);
if (be->be_state != BE_STATE_STOPPED)
{
LDAPDebug( LDAP_DEBUG_TRACE,
"ldbm_back_cleanup: warning - backend is in a wrong state - %d\n",
be->be_state, 0, 0 );
PR_Unlock (be->be_state_lock);
return 0;
}
slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
/* slapi_pblock_get( pb, SLAPI_SEQ_VAL, &directory );*/
return_value = dblayer_delete_database( li );
if (return_value == 0)
be->be_state = BE_STATE_DELETED;
PR_Unlock (be->be_state_lock);
return return_value;
}
示例9: mempool_get
/*
* get memory from memory pool
* The current code (#else) uses the memory pool stored in the
* per-thread-private data.
*/
void *
mempool_get(int type)
{
struct mempool_object *object = NULL;
struct mempool *my_mempool;
PR_ASSERT(type >= 0 && type < MEMPOOL_END);
if (!config_get_mempool_switch()) {
return NULL; /* memory pool: off */
}
#ifdef SHARED_MEMPOOL
if (NULL == mempool[type].mempool_mutex) {
/* mutex is NULL; this mempool is not enabled */
return NULL;
}
PR_Lock(mempool[type].mempool_mutex);
object = mempool[type].mempool_head;
if (NULL != object) {
mempool[type].mempool_head = object->mempool_next;
mempool[type].mempool_count--;
object->mempool_next = NULL;
}
PR_Unlock(mempool[type].mempool_mutex);
#else
my_mempool = (struct mempool *)PR_GetThreadPrivate(mempool_index);
if (NULL == my_mempool || my_mempool[0].mempool_name != mempool_names[0]) { /* mempool is not initialized */
return NULL;
}
object = my_mempool[type].mempool_head;
if (NULL != object) {
my_mempool[type].mempool_head = object->mempool_next;
my_mempool[type].mempool_count--;
object->mempool_next = NULL;
PR_SetThreadPrivate (mempool_index, (void *)my_mempool);
}
#endif
return object;
}
示例10: ConditionNotify
static PRIntervalTime ConditionNotify(PRUint32 loops)
{
PRThread *thread;
NotifyData notifyData;
PRIntervalTime timein, overhead;
timein = PR_IntervalNow();
notifyData.counter = loops;
notifyData.ml = PR_NewLock();
notifyData.child = PR_NewCondVar(notifyData.ml);
notifyData.parent = PR_NewCondVar(notifyData.ml);
thread = PR_CreateThread(
PR_USER_THREAD, Notifier, ¬ifyData,
PR_GetThreadPriority(PR_GetCurrentThread()),
thread_scope, PR_JOINABLE_THREAD, 0);
overhead = PR_IntervalNow() - timein; /* elapsed so far */
PR_Lock(notifyData.ml);
while (notifyData.counter > 0)
{
notifyData.pending = PR_TRUE;
PR_NotifyCondVar(notifyData.child);
while (notifyData.pending)
PR_WaitCondVar(notifyData.parent, PR_INTERVAL_NO_TIMEOUT);
}
PR_Unlock(notifyData.ml);
timein = PR_IntervalNow();
(void)PR_JoinThread(thread);
PR_DestroyCondVar(notifyData.child);
PR_DestroyCondVar(notifyData.parent);
PR_DestroyLock(notifyData.ml);
overhead += (PR_IntervalNow() - timein); /* more overhead */
return overhead;
} /* ConditionNotify */
示例11: IPC_Disconnect
nsresult
IPC_Disconnect()
{
// Must disconnect on same thread used to connect!
PR_ASSERT(gMainThread == PR_GetCurrentThread());
if (!gConnState || !gConnThread)
return NS_ERROR_NOT_INITIALIZED;
PR_Lock(gConnState->lock);
gConnState->shutdown = PR_TRUE;
PR_SetPollableEvent(gConnState->fds[POLL].fd);
PR_Unlock(gConnState->lock);
PR_JoinThread(gConnThread);
ConnDestroy(gConnState);
gConnState = NULL;
gConnThread = NULL;
return NS_OK;
}
示例12: PR_IMPLEMENT
/*
** Wait on a Semaphore.
**
** This routine allows a calling thread to wait or proceed depending upon the
** state of the semahore sem. The thread can proceed only if the counter value
** of the semaphore sem is currently greater than 0. If the value of semaphore
** sem is positive, it is decremented by one and the routine returns immediately
** allowing the calling thread to continue. If the value of semaphore sem is 0,
** the calling thread blocks awaiting the semaphore to be released by another
** thread.
**
** This routine can return PR_PENDING_INTERRUPT if the waiting thread
** has been interrupted.
*/
PR_IMPLEMENT(PRStatus) PR_WaitSem(PRSemaphore *sem)
{
PRStatus status = PR_SUCCESS;
#ifdef HAVE_CVAR_BUILT_ON_SEM
return _PR_MD_WAIT_SEM(&sem->md);
#else
PR_Lock(sem->cvar->lock);
while (sem->count == 0) {
sem->waiters++;
status = PR_WaitCondVar(sem->cvar, PR_INTERVAL_NO_TIMEOUT);
sem->waiters--;
if (status != PR_SUCCESS)
break;
}
if (status == PR_SUCCESS)
sem->count--;
PR_Unlock(sem->cvar->lock);
#endif
return (status);
}
示例13: CancelTimer
static PRBool CancelTimer(TimerEvent *timer)
{
PRBool canceled = PR_FALSE;
PR_Lock(tm_vars.ml);
timer->ref_count -= 1;
if (timer->links.prev == &timer->links)
{
while (timer->ref_count == 1)
{
PR_WaitCondVar(tm_vars.cancel_timer, PR_INTERVAL_NO_TIMEOUT);
}
}
else
{
PR_REMOVE_LINK(&timer->links);
canceled = PR_TRUE;
}
PR_Unlock(tm_vars.ml);
PR_DELETE(timer);
return canceled;
}
示例14: eq_enqueue
/*
* Add a new event to the event queue.
*/
static void
eq_enqueue(slapi_eq_context *newec)
{
slapi_eq_context **p;
PR_ASSERT(NULL != newec);
PR_Lock(eq->eq_lock);
/* Insert <newec> in order (sorted by start time) in the list */
for (p = &(eq->eq_queue); *p != NULL; p = &((*p)->ec_next)) {
if ((*p)->ec_when > newec->ec_when) {
break;
}
}
if (NULL != *p) {
newec->ec_next = *p;
} else {
newec->ec_next = NULL;
}
*p = newec;
PR_NotifyCondVar(eq->eq_cv); /* wake up scheduler thread */
PR_Unlock(eq->eq_lock);
}
示例15: _PR_FreeStack
/*
** Free the stack for the current thread
*/
void _PR_FreeStack(PRThreadStack *ts)
{
if (!ts) {
return;
}
if (ts->flags & _PR_STACK_PRIMORDIAL) {
PR_DELETE(ts);
return;
}
/*
** Put the stack on the free list. This is done because we are still
** using the stack. Next time a thread is created we will trim the
** list down; it's safe to do it then because we will have had to
** context switch to a live stack before another thread can be
** created.
*/
PR_Lock(_pr_stackLock);
PR_APPEND_LINK(&ts->links, _pr_freeStacks.prev);
_pr_numFreeStacks++;
PR_Unlock(_pr_stackLock);
}