diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-28 11:55:16 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-28 11:55:16 -0500 |
commit | 7c5e0f1834595a83053ffa7cad1a1947a2490b60 (patch) | |
tree | 75e2a6fbcf9154d617eb817d2ffcd7ef66137992 /bin/base_task.c | |
parent | 4d3ab322ccb00dede2b08f93a47dab47b68ef256 (diff) |
bin: add error checking to example tasks2007.3
Diffstat (limited to 'bin/base_task.c')
-rw-r--r-- | bin/base_task.c | 20 |
1 files changed, 16 insertions, 4 deletions
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 | ||