Mercurial > hg > beaglert
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/10-Instruments/d-box/prio.cpp Mon Jun 20 16:20:38 2016 +0100 @@ -0,0 +1,48 @@ +/* + * prio.cpp + * + * Created on: May 14, 2014 + * Author: Victor Zappi + */ + +#include "prio.h" +using namespace std; +//----------------------------------------------------------------------------------------------------------- +// set wanted real-time priority to this thread +//----------------------------------------------------------------------------------------------------------- +void set_realtime_priority(int order) +{ + int ret; + + // We'll operate on the currently running thread. + pthread_t this_thread = pthread_self(); + // struct sched_param is used to store the scheduling priority + struct sched_param params; + // We'll set the priority to the maximum. + params.sched_priority = sched_get_priority_max(SCHED_FIFO) - order; + + // Attempt to set thread real-time priority to the SCHED_FIFO policy + ret = pthread_setschedparam(this_thread, SCHED_FIFO, ¶ms); + if (ret != 0) { + // Print the error + cout << "Unsuccessful in setting thread realtime prio" << endl; + return; + } + + // Now verify the change in thread priority + int policy = 0; + ret = pthread_getschedparam(this_thread, &policy, ¶ms); + if (ret != 0) { + cout << "Couldn't retrieve real-time scheduling parameters" << endl; + return; + } + + // Check the correct policy was applied + if(policy != SCHED_FIFO) { + cout << "Scheduling is NOT SCHED_FIFO!" << endl; + } +} + +//----------------------------------------------------------------------------------------------------------- + +