void jsd_UnlockSourceTextSubsystem(JSDContext* jsdc) { #ifndef JSD_SIMULATION PR_ExitMonitor(jsd_text_mon); #endif /* JSD_SIMULATION */ }
nsresult nsTransactionManager::Unlock() { if (mMonitor) PR_ExitMonitor(mMonitor); return NS_OK; }
void Monitor::Exit() { if (0 == --mEntryCount) Release(); // protected by mMonitor PRStatus status = PR_ExitMonitor(mMonitor); NS_ASSERTION(PR_SUCCESS == status, "bad Monitor::Exit()"); }
static void T1Mon(void) { PRStatus rv; PRThread *t2, *t3; PR_fprintf(err, "\n**********************************\n"); PR_fprintf(err, " MONITORS\n"); PR_fprintf(err, "**********************************\n"); sharedM.o1 = PR_NewMonitor(); sharedM.o2 = PR_NewMonitor(); base = PR_IntervalNow(); PR_EnterMonitor(sharedM.o1); LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS); rv = PR_Wait(sharedM.o1, PR_SecondsToInterval(3)); if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv); else LogNow("T1 wait on o1 failed", rv); PR_ExitMonitor(sharedM.o1); LogNow("T1 creating T2", PR_SUCCESS); t2 = PR_CreateThread( PR_USER_THREAD, T2Mon, &sharedM, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); LogNow("T1 creating T3", PR_SUCCESS); t3 = PR_CreateThread( PR_USER_THREAD, T3Mon, &sharedM, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); PR_EnterMonitor(sharedM.o2); LogNow("T1 waiting forever on o2", PR_SUCCESS); rv = PR_Wait(sharedM.o2, PR_INTERVAL_NO_TIMEOUT); if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv); else LogNow("T1 wait on o2 failed", rv); PR_ExitMonitor(sharedM.o2); (void)PR_JoinThread(t2); (void)PR_JoinThread(t3); PR_DestroyMonitor(sharedM.o1); PR_DestroyMonitor(sharedM.o2); } /* T1Mon */
NS_IMETHODIMP nsIMAPHostSessionList::SetHaveWeEverDiscoveredFoldersForHost(const char *serverKey, bool discovered) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fHaveWeEverDiscoveredFolders = discovered; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::SetHostHasAdminURL(const char *serverKey, bool haveAdminURL) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fHaveAdminURL = haveAdminURL; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::SetHostIsUsingSubscription(const char *serverKey, bool usingSubscription) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fUsingSubscription = usingSubscription; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::SetShowDeletedMessagesForHost(const char *serverKey, bool showDeletedMessages) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fShowDeletedMessages = showDeletedMessages; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::SetDeleteIsMoveToTrashForHost(const char *serverKey, bool isMoveToTrash) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fDeleteIsMoveToTrash = isMoveToTrash; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::GetPasswordVerifiedOnline(const char *serverKey, bool &result) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) result = host->fPasswordVerifiedOnline; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::GetPasswordForHost(const char *serverKey, nsString &result) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) CopyASCIItoUTF16(nsDependentCString(host->fCachedPassword), result); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::SetCapabilityForHost(const char *serverKey, PRUint32 capability) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fCapabilityFlags = capability; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
void ReentrantMonitor::Exit() { if (--mEntryCount == 0) { Release(); // protected by mReentrantMonitor } PRStatus status = PR_ExitMonitor(mReentrantMonitor); NS_ASSERTION(PR_SUCCESS == status, "bad ReentrantMonitor::Exit()"); }
NS_IMETHODIMP nsIMAPHostSessionList::GetPasswordForHost(const char *serverKey, nsString &result) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) result.AssignWithConversion(host->fCachedPassword); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::AddNewNamespaceForHost(const char *serverKey, nsIMAPNamespace *ns) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fNamespaceList->AddNewNamespace(ns); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::GetOnlineTrashFolderExistsForHost(const char *serverKey, bool &result) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) result = host->fOnlineTrashFolderExists; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
static void PR_CALLBACK TryEntry(void *arg) { PRMonitor *ml = (PRMonitor*)arg; if (debug_mode) printf("Reentrant thread created\n"); PR_EnterMonitor(ml); if (debug_mode) printf("Reentrant thread acquired monitor\n"); PR_ExitMonitor(ml); if (debug_mode) printf("Reentrant thread released monitor\n"); } /* TryEntry */
NS_IMETHODIMP nsIMAPHostSessionList::FlushUncommittedNamespacesForHost(const char *serverKey, bool &result) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fTempNamespaceList->ClearNamespaces(true, true, true); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::SetShouldAlwaysListInboxForHost(const char *serverKey, bool shouldList) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fShouldAlwaysListInbox = shouldList; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::GetNamespaceNumberForHost(const char *serverKey, PRInt32 n, nsIMAPNamespace * &result) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) result = host->fNamespaceList->GetNamespaceNumber(n); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::SetNamespacesOverridableForHost(const char *serverKey, bool overridable) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fNamespacesOverridable = overridable; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::GetDefaultNamespaceOfTypeForHost(const char *serverKey, EIMAPNamespaceType type, nsIMAPNamespace * &result) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) result = host->fNamespaceList->GetDefaultNamespaceOfType(type); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
NS_IMETHODIMP nsIMAPHostSessionList::ClearServerAdvertisedNamespacesForHost(const char *serverKey) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fNamespaceList->ClearNamespaces(false, true, true); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
static void WaitMonitorThread(void *arg) { PRIntervalTime timeout = (PRIntervalTime) arg; PRIntervalTime elapsed; #if defined(XP_UNIX) || defined(WIN32) PRInt32 timeout_msecs = PR_IntervalToMilliseconds(timeout); PRInt32 elapsed_msecs; #endif #if defined(XP_UNIX) struct timeval end_time_tv; #endif #if defined(WIN32) && !defined(WINCE) struct _timeb end_time_tb; #endif PRMonitor *mon; mon = PR_NewMonitor(); if (mon == NULL) { fprintf(stderr, "PR_NewMonitor failed\n"); exit(1); } PR_EnterMonitor(mon); PR_Wait(mon, timeout); PR_ExitMonitor(mon); elapsed = (PRIntervalTime)(PR_IntervalNow() - start_time); if (elapsed + tolerance < timeout || elapsed > timeout + tolerance) { fprintf(stderr, "timeout wrong\n"); exit(1); } #if defined(XP_UNIX) gettimeofday(&end_time_tv, NULL); elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec) + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000; #endif #if defined(WIN32) #if defined(WINCE) elapsed_msecs = GetTickCount() - start_time_tick; #else _ftime(&end_time_tb); elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time) + (end_time_tb.millitm - start_time_tb.millitm); #endif #endif #if defined(XP_UNIX) || defined(WIN32) if (elapsed_msecs + tolerance_msecs < timeout_msecs || elapsed_msecs > timeout_msecs + tolerance_msecs) { fprintf(stderr, "timeout wrong\n"); exit(1); } #endif PR_DestroyMonitor(mon); if (debug_mode) { fprintf(stderr, "wait monitor thread (scope %d) done\n", PR_GetThreadScope(PR_GetCurrentThread())); } }
NS_IMETHODIMP nsIMAPHostSessionList::SetGotNamespacesForHost( const char *serverKey, PRBool gotNamespaces) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host) host->fGotNamespaces = gotNamespaces; PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
void aptCoreTrace::Log(eLogLevel eLevel, const char* fmt, ...) { static const int nEOL = 2; if (!mCanLog) return; if (eLevel < mCoreLogLevel) return; PRTime curTime = PR_Now(); PRExplodedTime localTime; PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime); PR_EnterMonitor(mLoggerLock); PRUint32 nWritten = PR_snprintf(mBuf, mBufSize-nEOL, "%02d:%02d:%02d %02d/%02d/%04d [%6d] [%s] ", // XXX i18n! localTime.tm_hour, localTime.tm_min, localTime.tm_sec, localTime.tm_month+1, localTime.tm_mday, localTime.tm_year, mPid, gsLogLevel[eLevel]); va_list arg_ptr; va_start(arg_ptr, fmt); PRUint32 nExtra = PR_vsnprintf(mBuf+nWritten, mBufSize-nWritten-nEOL, fmt, arg_ptr); va_end(arg_ptr); if (nExtra == (PRUint32) (-1)) { //failed? PR_ExitMonitor(mLoggerLock); return; } nWritten += nExtra; #ifdef _WIN32 mBuf[nWritten++] = '\r'; #endif mBuf[nWritten++] = '\n'; mLC->WriteLog(mBuf, nWritten); PR_ExitMonitor(mLoggerLock); }
NS_IMETHODIMP nsIMAPHostSessionList::ClearShellCacheForHost(const char *serverKey) { PR_EnterMonitor(gCachedHostInfoMonitor); nsIMAPHostInfo *host = FindHost(serverKey); if (host && host->fShellCache) host->fShellCache->Clear(); PR_ExitMonitor(gCachedHostInfoMonitor); return (host == NULL) ? NS_ERROR_ILLEGAL_VALUE : NS_OK; }
static void PR_CALLBACK TryEntry(void *arg) { PRMonitor *ml = (PRMonitor*)arg; if (debug_mode) PR_fprintf(std_err, "Reentrant thread created\n"); PR_EnterMonitor(ml); PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml); if (debug_mode) PR_fprintf(std_err, "Reentrant thread acquired monitor\n"); PR_ExitMonitor(ml); if (debug_mode) PR_fprintf(std_err, "Reentrant thread released monitor\n"); } /* TryEntry */
JSJ_DetachCurrentThreadFromJava(JSJavaThreadState *jsj_env) { SystemJavaVM *java_vm; JNIEnv* jEnv; JSJavaThreadState *e, **p; /* Disassociate the current native thread from its corresponding Java thread */ java_vm = jsj_env->jsjava_vm->java_vm; jEnv = jsj_env->jEnv; #ifdef JSJ_THREADSAFE PR_EnterMonitor(thread_list_monitor); #endif /* JSJ_THREADSAFE */ if (!JSJ_callbacks->detach_current_thread(java_vm, jEnv)) { #ifdef JSJ_THREADSAFE PR_ExitMonitor(thread_list_monitor); #endif /* JSJ_THREADSAFE */ return JS_FALSE; } /* Destroy the LiveConnect execution environment passed in */ jsj_ClearPendingJSErrors(jsj_env); for (p = &thread_list; (e = *p) != NULL; p = &(e->next)) { if (e == jsj_env) { *p = jsj_env->next; break; } } JS_ASSERT(e); #ifdef JSJ_THREADSAFE PR_ExitMonitor(thread_list_monitor); #endif /* JSJ_THREADSAFE */ free(jsj_env); return JS_TRUE; }
static void PR_CALLBACK MonitorContender(void *arg) { MonitorContentious_t *contention = (MonitorContentious_t*)arg; while (contention->loops-- > 0) { PR_EnterMonitor(contention->ml); contention->overhead += contention->interval; PR_Sleep(contention->interval); PR_ExitMonitor(contention->ml); } } /* MonitorContender */