3 * Copyright 2006,2007 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gruel/realtime.h>
37 #if defined(HAVE_SCHED_SETSCHEDULER)
42 enable_realtime_scheduling()
44 int policy = SCHED_FIFO;
45 int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2;
46 int pid = 0; // this process
48 struct sched_param param;
49 memset(¶m, 0, sizeof(param));
50 param.sched_priority = pri;
51 int result = sched_setscheduler(pid, policy, ¶m);
56 perror ("sched_setscheduler: failed to set real time priority");
57 return RT_OTHER_ERROR;
61 //printf("SCHED_FIFO enabled with priority = %d\n", pri);
67 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
75 enable_realtime_scheduling()
77 int policy = SCHED_FIFO;
78 int pri = (sched_get_priority_max (policy) +
79 sched_get_priority_min (policy)) / 2;
80 pthread_t this_thread = pthread_self (); // this process
81 struct sched_param param;
82 memset (¶m, 0, sizeof (param));
83 param.sched_priority = pri;
84 int result = pthread_setschedparam (this_thread, policy, ¶m);
89 perror ("pthread_setschedparam: failed to set real time priority");
90 return RT_OTHER_ERROR;
94 //printf("SCHED_FIFO enabled with priority = %d\n", pri);
99 // #elif // could try negative niceness
106 enable_realtime_scheduling()
108 return RT_NOT_IMPLEMENTED;