robert@464: /* robert@464: * prio.cpp robert@464: * robert@464: * Created on: May 14, 2014 robert@464: * Author: Victor Zappi robert@464: */ robert@464: robert@464: #include "prio.h" robert@464: using namespace std; robert@464: //----------------------------------------------------------------------------------------------------------- robert@464: // set wanted real-time priority to this thread robert@464: //----------------------------------------------------------------------------------------------------------- robert@464: void set_realtime_priority(int order) robert@464: { robert@464: int ret; robert@464: robert@464: // We'll operate on the currently running thread. robert@464: pthread_t this_thread = pthread_self(); robert@464: // struct sched_param is used to store the scheduling priority robert@464: struct sched_param params; robert@464: // We'll set the priority to the maximum. robert@464: params.sched_priority = sched_get_priority_max(SCHED_FIFO) - order; robert@464: robert@464: // Attempt to set thread real-time priority to the SCHED_FIFO policy robert@464: ret = pthread_setschedparam(this_thread, SCHED_FIFO, ¶ms); robert@464: if (ret != 0) { robert@464: // Print the error robert@464: cout << "Unsuccessful in setting thread realtime prio" << endl; robert@464: return; robert@464: } robert@464: robert@464: // Now verify the change in thread priority robert@464: int policy = 0; robert@464: ret = pthread_getschedparam(this_thread, &policy, ¶ms); robert@464: if (ret != 0) { robert@464: cout << "Couldn't retrieve real-time scheduling parameters" << endl; robert@464: return; robert@464: } robert@464: robert@464: // Check the correct policy was applied robert@464: if(policy != SCHED_FIFO) { robert@464: cout << "Scheduling is NOT SCHED_FIFO!" << endl; robert@464: } robert@464: } robert@464: robert@464: //----------------------------------------------------------------------------------------------------------- robert@464: robert@464: