525
527
if ((r = pthread_getschedparam(pthread_self(), &policy, &sp)) != 0) {
526
528
pa_log("pthread_getschedgetparam(): %s", pa_cstrerror(r));
530
sp.sched_priority = 1;
532
if (policy == SCHED_FIFO && sp.sched_priority >= rtprio) {
533
pa_log_info("Thread already being scheduled with SCHED_FIFO with priority %i.", sp.sched_priority);
537
sp.sched_priority = rtprio;
531
538
if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) != 0) {
540
while (sp.sched_priority > 1) {
541
sp.sched_priority --;
543
if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) == 0) {
544
pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i, which is lower than the requested %i.", sp.sched_priority, rtprio);
532
549
pa_log_warn("pthread_setschedparam(): %s", pa_cstrerror(r));
536
pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread.");
553
pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i.", sp.sched_priority);
541
#define NICE_LEVEL (-11)
543
/* Raise the priority of the current process as much as possible and
544
sensible: set the nice level to -15.*/
545
void pa_raise_priority(void) {
560
/* Raise the priority of the current process as much as possible that
561
* is <= the specified nice level..*/
562
int pa_raise_priority(int nice_level) {
547
564
#ifdef HAVE_SYS_RESOURCE_H
548
if (setpriority(PRIO_PROCESS, 0, NICE_LEVEL) < 0)
565
if (setpriority(PRIO_PROCESS, 0, nice_level) < 0) {
568
for (n = nice_level+1; n < 0; n++) {
570
if (setpriority(PRIO_PROCESS, 0, n) == 0) {
571
pa_log_info("Successfully acquired nice level %i, which is lower than the requested %i.", n, nice_level);
549
576
pa_log_warn("setpriority(): %s", pa_cstrerror(errno));
551
pa_log_info("Successfully gained nice level %i.", NICE_LEVEL);
580
pa_log_info("Successfully gained nice level %i.", nice_level);
554
583
#ifdef OS_IS_WIN32
555
if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
556
pa_log_warn("SetPriorityClass() failed: 0x%08X", GetLastError());
558
pa_log_info("Successfully gained high priority class.");
584
if (nice_level < 0) {
585
if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
586
pa_log_warn("SetPriorityClass() failed: 0x%08X", GetLastError());
589
pa_log_info("Successfully gained high priority class.");
562
596
/* Reset the priority to normal, inverting the changes made by
563
* pa_raise_priority() */
597
* pa_raise_priority() and pa_make_realtime()*/
564
598
void pa_reset_priority(void) {
599
#ifdef HAVE_SYS_RESOURCE_H
600
struct sched_param sp;
602
setpriority(PRIO_PROCESS, 0, 0);
604
memset(&sp, 0, sizeof(sp));
605
pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_OTHER, &sp) == 0);
565
608
#ifdef OS_IS_WIN32
566
609
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
569
#ifdef HAVE_SYS_RESOURCE_H
570
setpriority(PRIO_PROCESS, 0, 0);
574
613
/* Try to parse a boolean string value.*/