diff options
Diffstat (limited to 'bin/base_mt_task.c')
-rw-r--r-- | bin/base_mt_task.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/bin/base_mt_task.c b/bin/base_mt_task.c index 096b124..24f2070 100644 --- a/bin/base_mt_task.c +++ b/bin/base_mt_task.c | |||
@@ -12,6 +12,9 @@ | |||
12 | #include <stdio.h> | 12 | #include <stdio.h> |
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | 14 | ||
15 | /* Include gettid() */ | ||
16 | #include <sys/types.h> | ||
17 | |||
15 | /* Include threading support. */ | 18 | /* Include threading support. */ |
16 | #include <pthread.h> | 19 | #include <pthread.h> |
17 | 20 | ||
@@ -42,6 +45,19 @@ void* rt_thread(struct thread_context* ctx); | |||
42 | */ | 45 | */ |
43 | int job(void); | 46 | int job(void); |
44 | 47 | ||
48 | |||
49 | /* Catch errors. | ||
50 | */ | ||
51 | #define CALL( exp ) do { \ | ||
52 | int ret; \ | ||
53 | ret = exp; \ | ||
54 | if (ret != 0) \ | ||
55 | fprintf(stderr, "%s failed: %m\n", #exp);\ | ||
56 | else \ | ||
57 | fprintf(stderr, "%s ok.\n", #exp); \ | ||
58 | } while (0) | ||
59 | |||
60 | |||
45 | /* Basic setup is the same as in the single-threaded example. However, | 61 | /* Basic setup is the same as in the single-threaded example. However, |
46 | * we do some thread initiliazation first before invoking the job. | 62 | * we do some thread initiliazation first before invoking the job. |
47 | */ | 63 | */ |
@@ -105,6 +121,7 @@ int main(int argc, char** argv) | |||
105 | void* rt_thread(struct thread_context* ctx) | 121 | void* rt_thread(struct thread_context* ctx) |
106 | { | 122 | { |
107 | int do_exit; | 123 | int do_exit; |
124 | rt_param_t param; | ||
108 | 125 | ||
109 | /* Make presence visible. */ | 126 | /* Make presence visible. */ |
110 | printf("RT Thread %d active.\n", ctx->id); | 127 | printf("RT Thread %d active.\n", ctx->id); |
@@ -112,15 +129,17 @@ void* rt_thread(struct thread_context* ctx) | |||
112 | /***** | 129 | /***** |
113 | * 1) Initialize real-time settings. | 130 | * 1) Initialize real-time settings. |
114 | */ | 131 | */ |
115 | init_rt_thread(); | 132 | CALL( init_rt_thread() ); |
116 | sporadic_global(EXEC_COST, PERIOD); | 133 | CALL( sporadic_global(EXEC_COST, PERIOD) ); |
117 | |||
118 | 134 | ||
135 | /* Just for fun display the real-time parameters of this thread. */ | ||
136 | CALL( get_rt_task_param(gettid(), ¶m) ); | ||
137 | show_rt_param(¶m); | ||
119 | 138 | ||
120 | /***** | 139 | /***** |
121 | * 2) Transition to real-time mode. | 140 | * 2) Transition to real-time mode. |
122 | */ | 141 | */ |
123 | task_mode(LITMUS_RT_TASK); | 142 | CALL( task_mode(LITMUS_RT_TASK) ); |
124 | 143 | ||
125 | /* The task is now executing as a real-time task if the call didn't fail. | 144 | /* The task is now executing as a real-time task if the call didn't fail. |
126 | */ | 145 | */ |
@@ -142,7 +161,7 @@ void* rt_thread(struct thread_context* ctx) | |||
142 | /***** | 161 | /***** |
143 | * 4) Transition to background mode. | 162 | * 4) Transition to background mode. |
144 | */ | 163 | */ |
145 | task_mode(BACKGROUND_TASK); | 164 | CALL( task_mode(BACKGROUND_TASK) ); |
146 | 165 | ||
147 | 166 | ||
148 | return NULL; | 167 | return NULL; |