blob: 9fa8e19b7195ebc791f0fdc5db970d05906453e0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sched.h>
#include "litmus.h"
#include "internal.h"
#define SCHED_NORMAL 0
int task_mode(int mode)
{
struct sched_param param;
int me = gettid();
int policy = sched_getscheduler(gettid());
int old_mode = policy == SCHED_LITMUS ? LITMUS_RT_TASK : BACKGROUND_TASK;
memset(¶m, 0, sizeof(param));
param.sched_priority = 0;
if (old_mode == LITMUS_RT_TASK && mode == BACKGROUND_TASK) {
/* transition to normal task */
return sched_setscheduler(me, SCHED_NORMAL, ¶m);
} else if (old_mode == BACKGROUND_TASK && mode == LITMUS_RT_TASK) {
/* transition to RT task */
return sched_setscheduler(me, SCHED_LITMUS, ¶m);
} else {
errno = -EINVAL;
return -1;
}
}
|