]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_marte/tests/test_non_local_jump/test_fosa_long_jump.c
Migrating FOSA trunk to d-ac2v2. Phase 1 moving FRSH-FOSA to FOSA
[frescor/fosa.git] / src_marte / tests / test_non_local_jump / test_fosa_long_jump.c
index e7a7fd8fa4ea704da2a8782bfa16738a4f0d4e17..8848b61717136bcc66f9bb7c9717f679e9ae4d28 100644 (file)
 #include <unistd.h>
 #include <time.h> // For clock_nanosleep
 
-#include "frsh_error.h"
 #include "fosa.h"
-#include "frsh_fosa.h"
 #include "timespec_operations.h"
 
+#include <misc/error_checks.h>
+
+
+
 /*************************/
 /* D E F I N I T I O N S */
 /*************************/
@@ -39,10 +41,9 @@ static void work_under_a_interruptible_budget();
 
 int main()
 {
-    int terror = -1;
-    frsh_thread_attr_t periodic_attr;
-    frsh_signal_t signal_set[1];
-    frsh_thread_id_t periodic_tid;
+    fosa_thread_attr_t periodic_attr;
+    fosa_signal_t signal_set[1];
+    fosa_thread_id_t periodic_tid;
 
     memset(&context, 0, sizeof(context) );
 
@@ -53,12 +54,13 @@ int main()
 
     /* We set the signal mask */
     signal_set[0] = FOSA_LONG_JUMP_SIGNAL;
-    PRW(  fosa_set_accepted_signals(signal_set, 1) );
+
+    CHK(  fosa_set_accepted_signals(signal_set, 1) );
 
     /* We create a new thread with a given priority */
-    PRW(  frsh_thread_attr_init(&periodic_attr) );
-    PRW(  fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY)  );
-    PRW(  fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, NULL) );
+    CHK(  fosa_thread_attr_init(&periodic_attr) );
+    CHK(  fosa_thread_attr_set_prio(&periodic_attr, PERIODIC_THREAD_PRIORITY)  );
+    CHK(  fosa_thread_create(&periodic_tid, &periodic_attr, periodic_code, NULL) );
 
     printf("Main goes to sleep...\n");
 
@@ -72,13 +74,11 @@ int main()
 
 static void *periodic_code(void *thread_arg)
 {
-    int terror = -1;
-
     struct timespec period = {2, 500000000};  // 2.5 secs
-    frsh_thread_id_t jump_handler_thread;
+    fosa_thread_id_t jump_handler_thread;
 
-    frsh_signal_t jump_signal;
-    frsh_signal_info_t jump_signal_info;
+    fosa_signal_t jump_signal;
+    fosa_signal_info_t jump_signal_info;
 
     fosa_clock_id_t clock_id;
     fosa_timer_id_t jump_timer;
@@ -94,7 +94,7 @@ static void *periodic_code(void *thread_arg)
     /* - This creates the thread that will wait for */
     /*   FOSA_JUMP_SIGNAL                           */
     /************************************************/
-    PXW(  fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
+    CHK(  fosa_long_jump_install_handler(&jump_signal, &jump_handler_thread) );
     
     /* We create a budget timer using the thread's CPU clock */
     /*                                                       */
@@ -104,9 +104,9 @@ static void *periodic_code(void *thread_arg)
     /*                                                       */
     /* This signal is delivered to the handler thread.       */
     /*********************************************************/
-    PXW(  fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
+    CHK(  fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
     jump_signal_info.sival_ptr = &context;
-    PXW(  fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info, 
+    CHK(  fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info, 
                                           &jump_timer, jump_handler_thread)  );
 
     
@@ -124,7 +124,7 @@ static void *periodic_code(void *thread_arg)
         jumped = 0;
 
         /* For statistical purposes we read the activation time */
-        PXW(  fosa_clock_get_time(FOSA_CLOCK_REALTIME, &activation_time) );
+        CHK(  fosa_clock_get_time(FOSA_CLOCK_REALTIME, &activation_time) );
 
 
 
@@ -132,18 +132,18 @@ static void *periodic_code(void *thread_arg)
         /************************************/
 
         /* We arm the jump_timer */
-        PXW(  fosa_timer_arm(jump_timer, false, &budget) );
+        CHK(  fosa_timer_arm(jump_timer, false, &budget) );
 
         /* This is the point where the jump returns */
-        PXW(  fosa_long_jump_save_context(&context) );
+        CHK(  fosa_long_jump_save_context(&context) );
 
         /* Query if we come from a jump */
-        PXW(  fosa_long_jump_was_performed(&context, &jumped) );
+        CHK(  fosa_long_jump_was_performed(&context, &jumped) );
         if (!jumped)
         {
             /* HERE COMES THE WORK THAT CAN BE INTERRUPTED */
             work_under_a_interruptible_budget();
-            PRW(  fosa_timer_disarm(&jump_timer, NULL) );
+            CHK(  fosa_timer_disarm(jump_timer, NULL) );
             printf("NOT JUMPPED\n");
         }
         else
@@ -159,7 +159,7 @@ static void *periodic_code(void *thread_arg)
         
         /* Now we measure the time duration of the block */
         /*************************************************/
-        PXW(  fosa_clock_get_time(FOSA_CLOCK_REALTIME, &old_activation_time)  );
+        CHK(  fosa_clock_get_time(FOSA_CLOCK_REALTIME, &old_activation_time)  );
         decr_timespec(&old_activation_time, &activation_time);
         printf("Execution time: %6.3f\n", t2d(old_activation_time) );
     
@@ -183,17 +183,17 @@ static void work_under_a_interruptible_budget()
     i++;
     printf("Start regular work\n");
 
-    frsh_eat(&exec_time);
+    fosa_eat(&exec_time);
 
     /* Once in every 5 executions we work over the budget */
     if (i % 5 == 0)
     {
-        frsh_eat(&exec_time);
-        frsh_eat(&exec_time);
-        frsh_eat(&exec_time);
-        frsh_eat(&exec_time);
-        frsh_eat(&exec_time);
-        frsh_eat(&exec_time);
+        fosa_eat(&exec_time);
+        fosa_eat(&exec_time);
+        fosa_eat(&exec_time);
+        fosa_eat(&exec_time);
+        fosa_eat(&exec_time);
+        fosa_eat(&exec_time);
     }
 
     printf("End regular work\n");