set_rt_thread_priority
This function sets the operating system scheduling priority that the library uses to receive real-time data and run real-time callbacks. The setting applies from the next connect_rt_control. Without this call, the library uses the operating system’s default scheduling.
Definition
DRFLEx.h within class CDRFLEx, public section
bool set_rt_thread_priority(int nPolicy, int nPriority) { return _set_rt_thread_priority(_rbtCtrlUDP, nPolicy, nPriority); };
Parameter
Parameter Name |
Data Type |
Description |
|---|---|---|
nPolicy |
int |
Scheduling policy. |
nPriority |
int |
Scheduling priority. |
Return
Value |
Description |
|---|---|
1 |
The setting is stored and applies from the next connect_rt_control. |
0 |
Nothing changed. Real-time control is connected, the policy or priority is not valid, or (Linux) the process is not allowed to use the requested real-time priority. For an invalid or disallowed value, the library prints the reason to standard error. |
Caution
Call this function before connect_rt_control or after disconnect_rt_control. While real-time control is connected, it returns 0.
If the priority cannot be applied when connect_rt_control runs,
connect_rt_controlreturns 0 and closes the real-time connection.On Linux,
SCHED_FIFOandSCHED_RRneed permission to use real-time scheduling: theCAP_SYS_NICEcapability, or anRLIMIT_RTPRIOlimit of at leastnPriority(for example set withulimit -r).
Example
#include <sched.h>
// Receive RT data and run RT callbacks at SCHED_FIFO priority 80 (Linux).
if (!drfl.set_rt_thread_priority(SCHED_FIFO, 80)) {
printf("SCHED_FIFO 80 is not available.\n");
}
if (drfl.connect_rt_control("192.168.137.100", 12347)) {
drfl.start_rt_control();
}
In this example, the priority is set before the RT channel is connected, so it applies to that connection.
Tips
Use
set_rt_thread_priority(-1, 0)to return to the default scheduling for the next connection.