// -----------------------------------------------------------------------
-// Copyright (C) 2006 - 2008 FRESCOR consortium partners:
+// Copyright (C) 2006 - 2009 FRESCOR consortium partners:
//
// Universidad de Cantabria, SPAIN
// University of York, UK
/* S T A T I C V A R I A B L E S */
/**********************************/
static fosa_long_jump_context_t context;
-static void work_under_a_interruptible_budget();
+static void work_under_an_interruptible_budget();
int main()
/* We create a new thread with a given priority */
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) );
+ 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");
/*********************************************************/
CHK( fosa_thread_get_cputime_clock( fosa_thread_self(), &clock_id) );
jump_signal_info.sival_ptr = &context;
- CHK( fosa_timer_create_with_receiver(clock_id, jump_signal, jump_signal_info,
- &jump_timer, jump_handler_thread) );
+ CHK( fosa_timer_create_with_receiver
+ (clock_id, jump_signal, jump_signal_info,
+ &jump_timer, jump_handler_thread) );
+ printf("Start periodic work with budget=1400ms\n");
+
/* Periodic loop */
/*****************/
while (1)
if (!jumped)
{
/* HERE COMES THE WORK THAT CAN BE INTERRUPTED */
- work_under_a_interruptible_budget();
+ work_under_an_interruptible_budget();
CHK( fosa_timer_disarm(jump_timer, NULL) );
printf("NOT JUMPPED\n");
}
/* Now we measure the time duration of the block */
/*************************************************/
- CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_activation_time) );
- elapsed_time = fosa_abs_time_extract_interval(activation_time, after_activation_time);
- printf("Execution time: %ld msec\n", fosa_rel_time_to_msec(after_activation_time) );
+ CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_activation_time) );
+ elapsed_time = fosa_abs_time_extract_interval
+ (activation_time, after_activation_time);
+ printf("Execution time: %ld msec\n",
+ fosa_rel_time_to_msec(elapsed_time) );
/* And we program the next loop */
activation_time = fosa_abs_time_incr(activation_time, period);
activation_time_tspec = fosa_abs_time_to_timespec(activation_time);
- clock_nanosleep(FOSA_CLOCK_REALTIME, TIMER_ABSTIME, &activation_time_tspec,
- NULL);
+ clock_nanosleep(FOSA_CLOCK_REALTIME, TIMER_ABSTIME,
+ &activation_time_tspec,NULL);
}
return NULL;
// ------------------------------------------------------------------------------
-static void work_under_a_interruptible_budget()
+static void work_under_an_interruptible_budget()
{
static int i = 0;
fosa_rel_time_t exec_time = fosa_msec_to_rel_time(1000); // 1 sec
i++;
- printf("Start regular work\n");
+ printf("Start regular work (eat 1s)\n");
fosa_eat(&exec_time);
/* Once in every 5 executions we work over the budget */
if (i % 5 == 0)
{
- 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("Eat additional time (6s more) \n");
+ 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");