From: telleriam Date: Wed, 21 Nov 2007 17:31:50 +0000 (+0000) Subject: Reworking indentation of test_fosa_long_jump.c X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/fosa.git/commitdiff_plain/3bc75977170351acd54f42202faeda488ebd1862 Reworking indentation of test_fosa_long_jump.c git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@870 35b4ef3e-fd22-0410-ab77-dab3279adceb --- diff --git a/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c b/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c index 62f0cd3..59552ec 100644 --- a/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c +++ b/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c @@ -64,7 +64,7 @@ #include "frsh_fosa.h" #include "fosa_threads_and_signals.h" #include "fosa_clocks_and_timers.h" - +#include "fosa_configuration_parameters.h" #include "timespec_operations.h" @@ -84,7 +84,7 @@ /************************/ static fosa_long_jump_context_t context; -static int error_status; +static int error_status = 0; /************************/ @@ -92,6 +92,7 @@ static int error_status; /************************/ static void * thread_body(void *arg); +static void work(); /************************************************************************/ @@ -103,33 +104,44 @@ int main() //frsh_signal_t set[1]; frsh_thread_attr_t attr; - frsh_thread_id_t tid2; + frsh_thread_id_t tid_periodic_thread; int terror = 0; + frsh_signal_t signal_set[1]; + - // set signal mask - //set[0]=BUDGET_OVERRUN_SIGNAL; - //if (fosa_set_accepted_signals(set, 1) !=0) { - // printf ("Error while setting the signal mask\n"); - // exit (1); - //} + memset(&attr, 0, sizeof(attr) ); + memset(&tid_periodic_thread, 0, sizeof(tid_periodic_thread) ); + memset(&context, 0, sizeof(context) ); + memset(&signal_set, 0, sizeof(signal_set) ); - // Create the thread attributes object + /* Create the thread attributes object and assign the new thread a + priority lower than the main */ if (frsh_thread_attr_init (&attr) != 0) { - printf("Error while initializing the attributes\n"); - exit(1); + printf("Error while initializing the attributes\n"); + exit(1); } // set priority of periodic thread if (fosa_thread_attr_set_prio (&attr,fosa_get_priority_min()+3) != 0) { - printf("Error while setting schedparam\n"); - exit(1); + printf("Error while setting schedparam\n"); + exit(1); + } + + /* We set the priority of this main thread to a lever higher */ + /* than the future periodic thread. */ + /*************************************************************/ + if (fosa_thread_set_prio(fosa_thread_self(), fosa_get_priority_min() + 4) ) + { + printf("Error while changing main's priority\n"); + exit(1); } /* create the periodic thread */ - terror = fosa_thread_create(&tid2, &attr, thread_body, NULL); + /******************************/ + terror = fosa_thread_create(&tid_periodic_thread, &attr, thread_body, NULL); if (terror) { printf("pthread_create periodic thread\n"); - exit(1); + exit(1); } printf("Main goes to sleep...\n"); @@ -138,21 +150,6 @@ int main() return 0; } -// work to be aborted if too long -void work() { - static int i=0; - struct timespec exec_time={1,0}; // 1 second - - i++; - printf("start regular code %d\n",i); - // regular code - // eat one second of budget - frsh_eat(&exec_time); - // every five cycles eat an additional one second of budget */ - if (i%5==0) { - frsh_eat(&exec_time); - } -} @@ -173,73 +170,98 @@ static void * thread_body(void *thread_arg) int err; - fosa_clock_get_time(FOSA_CLOCK_REALTIME,&activation_time); + fosa_clock_get_time(FOSA_CLOCK_REALTIME, &activation_time); if (fosa_thread_get_cputime_clock(pthread_self(),&clockid) !=0) { - error_status=RT_ERROR_TIMER; - pthread_exit ( (void*)&error_status); + error_status=RT_ERROR_TIMER; + pthread_exit ( (void*)&error_status); } // install long jump handler if (fosa_long_jump_install_handler(&signal,&handler)!=0) { - error_status=RT_ERROR_HANDLER; - pthread_exit ( (void*)&error_status); + error_status=RT_ERROR_HANDLER; + pthread_exit ( (void*)&error_status); } // create budget timer siginfo.sival_ptr=(void *)(&context); if (fosa_timer_create_with_receiver - (clockid,signal,siginfo,&timerid,handler) != 0) - { - error_status=RT_ERROR_TIMER; - pthread_exit ( (void*)&error_status); - } + (clockid,signal,siginfo,&timerid,handler) != 0) + { + error_status=RT_ERROR_TIMER; + pthread_exit ( (void*)&error_status); + } printf("Start periodic thread body\n"); // main loop while(1) { + + jumped = 0; - // set the budget timer - if (fosa_timer_arm(timerid, false, &budget) != 0) { - error_status=RT_ERROR_TIMER; - pthread_exit ( (void*)&error_status); - } + // set the budget timer + if (fosa_timer_arm(timerid, false, &budget) != 0) { + error_status=RT_ERROR_TIMER; + pthread_exit ( (void*)&error_status); + } - printf("Begin thread main loop at %d,%d\n",(int)activation_time.tv_sec, - (int)(activation_time.tv_nsec/1000000)); + printf("Begin thread main loop at %d,%d\n",(int)activation_time.tv_sec, + (int)(activation_time.tv_nsec/1000000)); - // save context + // save context - err=fosa_long_jump_save_context(&context); - if (err!=0) { - error_status=RT_ERROR_HANDLER; - pthread_exit ( (void*)&error_status); - } - - err=fosa_long_jump_was_performed(&context,&jumped); - if (err!=0) { - error_status=RT_ERROR_HANDLER; - pthread_exit ( (void*)&error_status); - } - if (!jumped) { - work(); - } else { - // code executed if asynchronous jump instruction invoked */ - printf("Aborted thread OEEEEEEEEEEEEEEEEEEEE\n"); - } - - printf("after abortable block\n"); - fosa_clock_get_time(FOSA_CLOCK_REALTIME,&old_activation_time); - decr_timespec(&old_activation_time,&activation_time); - printf("End thread %6.3f\n",old_activation_time.tv_sec+(float) - (float)old_activation_time.tv_nsec/1000000000.0); - // sleep for a while - incr_timespec(&activation_time,&period); - clock_nanosleep(FOSA_CLOCK_REALTIME,TIMER_ABSTIME, - &activation_time,&old_activation_time); + err=fosa_long_jump_save_context(&context); + if (err!=0) { + error_status=RT_ERROR_HANDLER; + pthread_exit ( (void*)&error_status); + } + + err=fosa_long_jump_was_performed(&context,&jumped); + if (err!=0) { + error_status=RT_ERROR_HANDLER; + pthread_exit ( (void*)&error_status); + } + if (!jumped) { + work(); + } else { + // code executed if asynchronous jump instruction invoked */ + printf("Aborted thread\n"); + } + + printf("after abortable block\n"); + fosa_clock_get_time(FOSA_CLOCK_REALTIME,&old_activation_time); + decr_timespec(&old_activation_time,&activation_time); + printf("End thread %6.3f\n",old_activation_time.tv_sec+(float) + (float)old_activation_time.tv_nsec/1000000000.0); + // sleep for a while + incr_timespec(&activation_time,&period); + clock_nanosleep(FOSA_CLOCK_REALTIME,TIMER_ABSTIME, + &activation_time,&old_activation_time); } // while } + +// --------------------------------------------------------------------- + +// work to be aborted if too long +static void work() +{ + static int i=0; + struct timespec exec_time={1,0}; // 1 second + + i++; + printf("start regular code %d\n",i); + // regular code + // eat one second of budget + frsh_eat(&exec_time); + // every five cycles eat an additional one second of 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); + } +}