Statistics
| Branch: | Revision:

ddr4s / fw / wiringPi / wiringPi / piHiPri.c @ 32:cadb9025f1e0

History | View | Annotate | Download (1.58 KB)

1
/*
2
 * piHiPri:
3
 *        Simple way to get your program running at high priority
4
 *        with realtime schedulling.
5
 *
6
 *        Copyright (c) 2012 Gordon Henderson
7
 ***********************************************************************
8
 * This file is part of wiringPi:
9
 *        https://projects.drogon.net/raspberry-pi/wiringpi/
10
 *
11
 *    wiringPi is free software: you can redistribute it and/or modify
12
 *    it under the terms of the GNU Lesser General Public License as
13
 *    published by the Free Software Foundation, either version 3 of the
14
 *    License, or (at your option) any later version.
15
 *
16
 *    wiringPi is distributed in the hope that it will be useful,
17
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *    GNU Lesser General Public License for more details.
20
 *
21
 *    You should have received a copy of the GNU Lesser General Public
22
 *    License along with wiringPi.
23
 *    If not, see <http://www.gnu.org/licenses/>.
24
 ***********************************************************************
25
 */
26

    
27
#include <sched.h>
28
#include <string.h>
29

    
30
#include "wiringPi.h"
31

    
32

    
33
/*
34
 * piHiPri:
35
 *        Attempt to set a high priority schedulling for the running program
36
 *********************************************************************************
37
 */
38

    
39
int piHiPri (const int pri)
40
{
41
  struct sched_param sched ;
42

    
43
  memset (&sched, 0, sizeof(sched)) ;
44

    
45
  if (pri > sched_get_priority_max (SCHED_RR))
46
    sched.sched_priority = sched_get_priority_max (SCHED_RR) ;
47
  else
48
    sched.sched_priority = pri ;
49

    
50
  return sched_setscheduler (0, SCHED_RR, &sched) ;
51
}