comparison examples/10-Instruments/d-box/prio.cpp @ 464:8fcfbfb32aa0 prerelease

Examples reorder with subdirectories. Added header to each project. Moved Doxygen to bottom of render.cpp.
author Robert Jack <robert.h.jack@gmail.com>
date Mon, 20 Jun 2016 16:20:38 +0100
parents
children
comparison
equal deleted inserted replaced
463:c47709e8b5c9 464:8fcfbfb32aa0
1 /*
2 * prio.cpp
3 *
4 * Created on: May 14, 2014
5 * Author: Victor Zappi
6 */
7
8 #include "prio.h"
9 using namespace std;
10 //-----------------------------------------------------------------------------------------------------------
11 // set wanted real-time priority to this thread
12 //-----------------------------------------------------------------------------------------------------------
13 void set_realtime_priority(int order)
14 {
15 int ret;
16
17 // We'll operate on the currently running thread.
18 pthread_t this_thread = pthread_self();
19 // struct sched_param is used to store the scheduling priority
20 struct sched_param params;
21 // We'll set the priority to the maximum.
22 params.sched_priority = sched_get_priority_max(SCHED_FIFO) - order;
23
24 // Attempt to set thread real-time priority to the SCHED_FIFO policy
25 ret = pthread_setschedparam(this_thread, SCHED_FIFO, &params);
26 if (ret != 0) {
27 // Print the error
28 cout << "Unsuccessful in setting thread realtime prio" << endl;
29 return;
30 }
31
32 // Now verify the change in thread priority
33 int policy = 0;
34 ret = pthread_getschedparam(this_thread, &policy, &params);
35 if (ret != 0) {
36 cout << "Couldn't retrieve real-time scheduling parameters" << endl;
37 return;
38 }
39
40 // Check the correct policy was applied
41 if(policy != SCHED_FIFO) {
42 cout << "Scheduling is NOT SCHED_FIFO!" << endl;
43 }
44 }
45
46 //-----------------------------------------------------------------------------------------------------------
47
48