aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-28 11:55:16 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-28 11:55:16 -0500
commit7c5e0f1834595a83053ffa7cad1a1947a2490b60 (patch)
tree75e2a6fbcf9154d617eb817d2ffcd7ef66137992
parent4d3ab322ccb00dede2b08f93a47dab47b68ef256 (diff)
bin: add error checking to example tasks2007.3
-rw-r--r--bin/base_mt_task.c29
-rw-r--r--bin/base_task.c20
2 files changed, 40 insertions, 9 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 */
43int job(void); 46int 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)
105void* rt_thread(struct thread_context* ctx) 121void* 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(), &param) );
137 show_rt_param(&param);
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;
diff --git a/bin/base_task.c b/bin/base_task.c
index 067c088..c50990b 100644
--- a/bin/base_task.c
+++ b/bin/base_task.c
@@ -26,6 +26,18 @@
26#define PERIOD 100 26#define PERIOD 100
27#define EXEC_COST 10 27#define EXEC_COST 10
28 28
29/* Catch errors.
30 */
31#define CALL( exp ) do { \
32 int ret; \
33 ret = exp; \
34 if (ret != 0) \
35 fprintf(stderr, "%s failed: %m\n", #exp);\
36 else \
37 fprintf(stderr, "%s ok.\n", #exp); \
38 } while (0)
39
40
29/* Declare the periodically invoked job. 41/* Declare the periodically invoked job.
30 * Returns 1 -> task should exit. 42 * Returns 1 -> task should exit.
31 * 0 -> task should continue. 43 * 0 -> task should continue.
@@ -72,8 +84,8 @@ int main(int argc, char** argv)
72 * If this were to execute under a partitioned scheduler, it would be assigned 84 * If this were to execute under a partitioned scheduler, it would be assigned
73 * to the first partition (since partitioning is performed offline). 85 * to the first partition (since partitioning is performed offline).
74 */ 86 */
75 init_litmus(); 87 CALL( init_litmus() );
76 sporadic_global(EXEC_COST, PERIOD); 88 CALL( sporadic_global(EXEC_COST, PERIOD) );
77 89
78 /* To specify a partition, use sporadic_partitioned(). 90 /* To specify a partition, use sporadic_partitioned().
79 * Example: 91 * Example:
@@ -88,7 +100,7 @@ int main(int argc, char** argv)
88 /***** 100 /*****
89 * 4) Transition to real-time mode. 101 * 4) Transition to real-time mode.
90 */ 102 */
91 task_mode(LITMUS_RT_TASK); 103 CALL( task_mode(LITMUS_RT_TASK) );
92 104
93 /* The task is now executing as a real-time task if the call didn't fail. 105 /* The task is now executing as a real-time task if the call didn't fail.
94 */ 106 */
@@ -110,7 +122,7 @@ int main(int argc, char** argv)
110 /***** 122 /*****
111 * 6) Transition to background mode. 123 * 6) Transition to background mode.
112 */ 124 */
113 task_mode(BACKGROUND_TASK); 125 CALL( task_mode(BACKGROUND_TASK) );
114 126
115 127
116 128