void DOMStorageDBThread::SetDefaultPriority() { if (--mPriorityCounter <= 0) { PR_SetThreadPriority(mThread, PR_PRIORITY_LOW); } }
static void RudimentaryTests(void) { /* ** Try some rudimentary tests like setting valid priority and ** getting it back, or setting invalid priorities and getting ** back a valid answer. */ PRThreadPriority priority; PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_URGENT); priority = PR_GetThreadPriority(PR_GetCurrentThread()); failed = ((PR_TRUE == failed) || (PR_PRIORITY_URGENT != priority)) ? PR_TRUE : PR_FALSE; if (debug_mode && (PR_PRIORITY_URGENT != priority)) { PR_fprintf(debug_out, "PR_[S/G]etThreadPriority() failed\n"); } PR_SetThreadPriority( PR_GetCurrentThread(), (PRThreadPriority)(PR_PRIORITY_FIRST - 1)); priority = PR_GetThreadPriority(PR_GetCurrentThread()); failed = ((PR_TRUE == failed) || (PR_PRIORITY_FIRST != priority)) ? PR_TRUE : PR_FALSE; if (debug_mode && (PR_PRIORITY_FIRST != priority)) { PR_fprintf(debug_out, "PR_SetThreadPriority(-1) failed\n"); } PR_SetThreadPriority( PR_GetCurrentThread(), (PRThreadPriority)(PR_PRIORITY_LAST + 1)); priority = PR_GetThreadPriority(PR_GetCurrentThread()); failed = ((PR_TRUE == failed) || (PR_PRIORITY_LAST != priority)) ? PR_TRUE : PR_FALSE; if (debug_mode && (PR_PRIORITY_LAST != priority)) { PR_fprintf(debug_out, "PR_SetThreadPriority(+1) failed\n"); } } /* RudimentataryTests */
void DOMStorageDBThread::SetHigherPriority() { ++mPriorityCounter; PR_SetThreadPriority(mThread, PR_PRIORITY_URGENT); }
SECStatus do_accepts( PRFileDesc *listen_sock, PRFileDesc *model_sock, int requestCert ) { PRNetAddr addr; PRErrorCode perr; #ifdef XP_UNIX struct sigaction act; #endif VLOG(("selfserv: do_accepts: starting")); PR_SetThreadPriority( PR_GetCurrentThread(), PR_PRIORITY_HIGH); acceptorThread = PR_GetCurrentThread(); #ifdef XP_UNIX /* set up the signal handler */ act.sa_handler = sigusr1_handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; if (sigaction(SIGUSR1, &act, NULL)) { fprintf(stderr, "Error installing signal handler.\n"); exit(1); } #endif while (!stopping) { PRFileDesc *tcp_sock; PRCList *myLink; FPRINTF(stderr, "\n\n\nselfserv: About to call accept.\n"); tcp_sock = PR_Accept(listen_sock, &addr, PR_INTERVAL_NO_TIMEOUT); if (tcp_sock == NULL) { perr = PR_GetError(); if ((perr != PR_CONNECT_RESET_ERROR && perr != PR_PENDING_INTERRUPT_ERROR) || verbose) { errWarn("PR_Accept"); } if (perr == PR_CONNECT_RESET_ERROR) { FPRINTF(stderr, "Ignoring PR_CONNECT_RESET_ERROR error - continue\n"); continue; } stopping = 1; break; } VLOG(("selfserv: do_accept: Got connection\n")); PZ_Lock(qLock); while (PR_CLIST_IS_EMPTY(&freeJobs) && !stopping) { PZ_WaitCondVar(freeListNotEmptyCv, PR_INTERVAL_NO_TIMEOUT); } if (stopping) { PZ_Unlock(qLock); if (tcp_sock) { PR_Close(tcp_sock); } break; } myLink = PR_LIST_HEAD(&freeJobs); PR_REMOVE_AND_INIT_LINK(myLink); /* could release qLock here and reacquire it 7 lines below, but ** why bother for 4 assignment statements? */ { JOB * myJob = (JOB *)myLink; myJob->tcp_sock = tcp_sock; myJob->model_sock = model_sock; myJob->requestCert = requestCert; } PR_APPEND_LINK(myLink, &jobQ); PZ_NotifyCondVar(jobQNotEmptyCv); PZ_Unlock(qLock); } FPRINTF(stderr, "selfserv: Closing listen socket.\n"); VLOG(("selfserv: do_accepts: exiting")); if (listen_sock) { PR_Close(listen_sock); } return SECSuccess; }
void RCThread::SetPriority(RCThread::Priority new_priority) { PR_SetThreadPriority(identity, (PRThreadPriority)new_priority); }
int main(int argc, char **argv) #endif { PLOptStatus os; PRIntn duration = DEFAULT_DURATION; PRUint32 totalCount, highCount = 0, lowCount = 0; PLOptState *opt = PL_CreateOptState(argc, argv, "hdc:"); debug_out = PR_STDOUT; oneSecond = PR_SecondsToInterval(1); while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { if (PL_OPT_BAD == os) continue; switch (opt->option) { case 'd': /* debug mode */ debug_mode = PR_TRUE; break; case 'c': /* test duration */ duration = atoi(opt->value); break; case 'h': /* help message */ default: Help(); return 2; } } PL_DestroyOptState(opt); PR_STDIO_INIT(); if (duration == 0) duration = DEFAULT_DURATION; RudimentaryTests(); printf("Priority test: running for %d seconds\n\n", duration); (void)PerSecond(PR_IntervalNow()); totalCount = PerSecond(PR_IntervalNow()); PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_URGENT); if (debug_mode) { PR_fprintf(debug_out, "The high priority thread should get approximately three\n"); PR_fprintf( debug_out, "times what the low priority thread manages. A maximum of \n"); PR_fprintf( debug_out, "%d cycles are available.\n\n", totalCount); } duration = (duration + 4) / 5; CreateThreads(&lowCount, &highCount); while (duration--) { PRIntn loop = 5; while (loop--) PR_Sleep(oneSecond); if (debug_mode) PR_fprintf(debug_out, "high : low :: %d : %d\n", highCount, lowCount); } PR_ProcessExit((failed) ? 1 : 0); PR_NOT_REACHED("You can't get here -- but you did!"); return 1; /* or here */ } /* main */