aboutsummaryrefslogtreecommitdiffstats
path: root/src/task.c
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-23 11:16:40 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-23 11:16:40 -0500
commitd56b86e42b72abb68ba74bf540ddc259f6b20f84 (patch)
treea9d78e760bcf4254d883c6242d384f9d1261098f /src/task.c
parent23701920e39a903883f19c2749383bba2a746405 (diff)
reorganize liblitmus to be more modular
Diffstat (limited to 'src/task.c')
-rw-r--r--src/task.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/task.c b/src/task.c
new file mode 100644
index 0000000..47d68e1
--- /dev/null
+++ b/src/task.c
@@ -0,0 +1,72 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <unistd.h>
4
5#include "litmus.h"
6#include "internal.h"
7
8static void tperrorx(char* msg)
9{
10 fprintf(stderr,
11 "Task %d: %s: %m",
12 getpid(), msg);
13 exit(-1);
14}
15
16/* common launch routine */
17int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup,
18 void* setup_arg)
19{
20 int ret;
21 int rt_task = fork();
22
23 if (rt_task == 0) {
24 /* we are the real-time task
25 * launch task and die when it is done
26 */
27 rt_task = getpid();
28 ret = setup(rt_task, setup_arg);
29 if (ret < 0)
30 tperrorx("could not setup task parameters");
31 ret = task_mode(LITMUS_RT_TASK);
32 if (ret < 0)
33 tperrorx("could not become real-time task");
34 exit(rt_prog(rt_arg));
35 }
36
37 return rt_task;
38}
39
40struct create_rt_param {
41 int cpu;
42 int wcet;
43 int period;
44 task_class_t class;
45};
46
47int setup_create_rt(int pid, struct create_rt_param* arg)
48{
49 rt_param_t params;
50 params.period = arg->period;
51 params.exec_cost = arg->wcet;
52 params.cpu = arg->cpu;
53 params.cls = arg->class;
54 return set_rt_task_param(pid, &params);
55}
56
57int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period,
58 task_class_t class)
59{
60 struct create_rt_param params;
61 params.cpu = cpu;
62 params.period = period;
63 params.wcet = wcet;
64 params.class = class;
65 return __launch_rt_task(rt_prog, arg,
66 (rt_setup_fn_t) setup_create_rt, &params);
67}
68
69int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) {
70 return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD);
71}
72