]> rtime.felk.cvut.cz Git - frescor/fosa.git/commitdiff
FOSA-PaRTiKle: adaptation to the FOSA time abstraction
authorbrocalv <brocalv@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 12 May 2008 13:59:00 +0000 (13:59 +0000)
committerbrocalv <brocalv@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 12 May 2008 13:59:00 +0000 (13:59 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1163 35b4ef3e-fd22-0410-ab77-dab3279adceb

src_partikle/Makefile
src_partikle/fosa_app_def_sched.c
src_partikle/fosa_clocks_and_timers.c
src_partikle/fosa_mutexes_and_condvars.c
src_partikle/fosa_threads_and_signals.c
src_partikle/fosa_time.c [new file with mode: 0644]

index e157c9820f42808945fd870c4974a9e74df171d7..3297cd97b96e9f016136829b83a633bea01f4ede 100644 (file)
@@ -1,7 +1,7 @@
 include ../config.mk
 include ../rules.mk
 
-FOSA_MODULES=fosa_clocks_and_timers fosa_threads_and_signals fosa_app_def_sched fosa_mutexes_and_condvars fosa_misc fosa_long_jump
+FOSA_MODULES=fosa_clocks_and_timers fosa_threads_and_signals fosa_app_def_sched fosa_mutexes_and_condvars fosa_misc fosa_long_jump fosa_time
 FOSA_OBJS=$(addsuffix .o,$(FOSA_MODULES))
 
 check_gcc = $(shell \
index c47296e7a9d3bdf19d9a554c96d03ec7c0a832a2..99c3dc5d41310d3721a08b93eb80e485ce81ac9d 100644 (file)
@@ -60,6 +60,8 @@
 #include <fosa_configuration_parameters.h>
 #include <fosa_app_def_sched.h>
 #include <fosa_threads_and_signals.h>
+#include <fosa_time.h>
+
 #include <sched.h>
 #include <signal.h>
 #include <unistd.h>
@@ -472,21 +474,21 @@ int fosa_adsactions_add_suspend
        return posix_appsched_actions_addsuspend (&(sched_actions -> actions), thread);
 }
 
-int fosa_adsactions_add_timeout 
+int fosa_adsactions_add_timeout
                (fosa_ads_actions_t *sched_actions,
                 fosa_clock_id_t clock_id,
-                const struct timespec *at_time)
+                const fosa_abs_time_t *at_time)
 {
-       sched_actions -> timeout = *at_time;
+       sched_actions -> timeout = fosa_abs_time_to_timespec (*at_time);
        sched_actions -> timeout_ptr = &(sched_actions -> timeout);
        return 0;
 }
 
-int fosa_adsactions_add_thread_notification
+int fosa_adsactions_add_thread_notification 
                (fosa_ads_actions_t *sched_actions,
                 fosa_thread_id_t thread,
                 fosa_clock_id_t clock_id,
-                const struct timespec *at_time)
+                const fosa_abs_time_t *at_time)
 {
        printf ("BUG: fosa_adsactions_add_thread_notification: Not implemented\n");
         exit (-21);
index f0284621f6875a06f7ef0f6029f6d6fbdec410fe..a5e051c31962ea96232c28fc125f5066f1bd11ea 100644 (file)
 //================================================
 
 #include <fosa_clocks_and_timers.h>
+#include <fosa_time.h>
+#include <stdlib.h>
 
 /*************************
  * Timing: Clocks
  *************************/
-int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec *current_time)
-{
-       if (clock_gettime (clockid, current_time))
-               return FOSA_EINVAL;
+int fosa_clock_get_time(fosa_clock_id_t clockid, fosa_abs_time_t *current_time)
+{      
+       int err;
+       struct timespec now;
+       
+       err = clock_gettime (clockid, &now);
+       *current_time = fosa_timespec_to_abs_time(now);
        
        return 0;
 }
@@ -119,42 +124,47 @@ int fosa_timer_delete(fosa_timer_id_t timerid)
 }
 
 
-int fosa_timer_arm
-               (fosa_timer_id_t timerid, bool abstime,
-                const struct timespec *value)
+int fosa_rel_timer_arm (fosa_timer_id_t timerid, const fosa_rel_time_t *value)
 {
-       struct timespec now;
+       struct itimerspec tvalue; 
        
-       clock_gettime (CLOCK_REALTIME, &now);
+       tvalue.it_value = fosa_rel_time_to_timespec(*value);
+       tvalue.it_interval = (struct timespec) {0,0};
        
-       struct itimerspec tvalue =
-       {
-               .it_value = (struct timespec) *value,
-               .it_interval = {0,0},
-       };
+       if (timer_settime (timerid, 0, &tvalue, NULL))
+               return FOSA_EINVAL;
+       
+       return 0;
+}
+
+int fosa_abs_timer_arm (fosa_timer_id_t timerid, const fosa_abs_time_t *value)
+{
+       struct itimerspec tvalue; 
        
-       if (timer_settime (timerid, abstime, &tvalue, NULL))
-               return EINVAL;
+       tvalue.it_value = fosa_abs_time_to_timespec(*value);
+       tvalue.it_interval = (struct timespec) {0,0};
+       
+       if (timer_settime (timerid, TIMER_ABSTIME, &tvalue, NULL))
+               return FOSA_EINVAL;
        
        return 0;
 }
 
 
 int fosa_timer_get_remaining_time
-               (fosa_timer_id_t timerid, struct timespec *remaining_time)
+               (fosa_timer_id_t timerid, fosa_rel_time_t *remaining_time)
 {
        struct itimerspec value;
        
        if (timer_gettime (timerid, &value))
-               return EINVAL;
+               return FOSA_EINVAL;
        
-       *remaining_time = value.it_value;
+       *remaining_time = fosa_timespec_to_rel_time (value.it_value);
        return 0;
 }
 
 
-int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec
-               *remaining_time)
+int fosa_timer_disarm (fosa_timer_id_t timerid, fosa_rel_time_t *remaining_time)
 {
        struct itimerspec null_timer, old;
        
@@ -165,10 +175,10 @@ int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec
        };
        
        if (timer_settime (timerid, 0, &null_timer, &old))
-               return EINVAL;
+               return FOSA_EINVAL;
        
        if (remaining_time)
-               *remaining_time = old.it_value; 
+               *remaining_time = fosa_timespec_to_rel_time (old.it_value);
                
        return 0;
 }
index ce75869e3b6425e0bf0fc6f20e110223c2023231..4b14c78a7b97e877e7c6674d698e8818a0ae4233 100644 (file)
@@ -58,6 +58,7 @@
 //================================================
 
 #include <fosa_mutexes_and_condvars.h>
+#include <fosa_time.h>
 
 /*******************************************************
  * Mutexes with priority ceiling
@@ -147,19 +148,18 @@ int fosa_cond_wait(fosa_cond_t *cond, fosa_mutex_t *mutex)
        return pthread_cond_wait (cond, mutex);
 }
 
-int fosa_cond_timedwait 
-               (fosa_cond_t *cond, 
-                fosa_mutex_t *mutex,
-                const struct timespec *abstime)
+int fosa_cond_timedwait (fosa_cond_t *cond, fosa_mutex_t *mutex,
+                       const fosa_abs_time_t *abstime)
 {
        int err;
+       struct timespec tout = fosa_abs_time_to_timespec (*abstime);
        
-       err = pthread_cond_timedwait (cond, mutex, abstime);
+       err = pthread_cond_timedwait (cond, mutex, &tout);
        if (err == ETIMEDOUT)
-               return ETIMEDOUT;
+               return FOSA_ETIMEDOUT;
 
        if (err)
-               return EINVAL;
+               return FOSA_EINVAL;
        
        return 0;
 }
index e95df0169aff712ccd94b291f36c7a9016844973..d48561b832ca41e669571cc81844886e17c9a1d5 100644 (file)
@@ -59,6 +59,7 @@
 
 #include <fosa_configuration_parameters.h>
 #include <fosa_threads_and_signals.h>
+#include <fosa_time.h>
 #include <unistd.h>
 #include <signal.h>
 
@@ -298,12 +299,13 @@ int fosa_signal_queue
 }
 
  int fosa_signal_timedwait
-     (fosa_signal_t set[], int size, fosa_signal_t *signal_received, 
-      fosa_signal_info_t *info, const struct timespec *timeout)
+       (fosa_signal_t set[], int size, fosa_signal_t *signal_received,
+        fosa_signal_info_t *info, const fosa_rel_time_t *timeout)
 {
        int i, sig;
        sigset_t wset;
        siginfo_t nfo;
+       struct timespec tout = fosa_rel_time_to_timespec (*timeout);
        
        if (size < 0) 
                return EINVAL;
@@ -315,7 +317,7 @@ int fosa_signal_queue
                sigaddset (&wset, set [i]);
        }
        
-       sig = sigtimedwait (&wset, &nfo, timeout);
+       sig = sigtimedwait (&wset, &nfo, &tout);
        if (sig == -1)
                return errno;
        
diff --git a/src_partikle/fosa_time.c b/src_partikle/fosa_time.c
new file mode 100644 (file)
index 0000000..d63f84e
--- /dev/null
@@ -0,0 +1,93 @@
+//----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2007 by the FRESCOR consortium:
+//
+//    Universidad de Cantabria,              SPAIN
+//    University of York,                    UK
+//    Scuola Superiore Sant'Anna,            ITALY
+//    Kaiserslautern University,             GERMANY
+//    Univ. Politecnica  Valencia,           SPAIN
+//    Czech Technical University in Prague,  CZECH REPUBLIC
+//    ENEA                                   SWEDEN
+//    Thales Communication S.A.              FRANCE
+//    Visual Tools S.A.                      SPAIN
+//    Rapita Systems Ltd                     UK
+//    Evidence                               ITALY
+//
+//    See http://www.frescor.org
+//
+//        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+//        in part by the European Union Sixth Framework Programme
+//        The European Union is not liable of any use that may be
+//        made of this code.
+//
+//
+//  based on previous work (FSF) done in the FIRST project
+//
+//   Copyright (C) 2005  Mälardalen University, SWEDEN
+//                       Scuola Superiore S.Anna, ITALY
+//                       Universidad de Cantabria, SPAIN
+//                       University of York, UK
+//
+// This file is part of FOSA (Frsh Operating System Abstraction)
+//
+// FOSA is free software; you can redistribute it and/or modify it
+// under terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option) any
+// later version.  FOSA is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details. You should have received a
+// copy of the GNU General Public License along with FOSA; see file
+// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+// Cambridge, MA 02139, USA.
+//
+// As a special exception, including FOSA header files in a file,
+// instantiating FOSA generics or templates, or linking other files
+// with FOSA objects to produce an executable application, does not
+// by itself cause the resulting executable application to be covered
+// by the GNU General Public License. This exception does not
+// however invalidate any other reasons why the executable file might be
+// covered by the GNU Public License.
+// -----------------------------------------------------------------------
+// fosa_time.c
+//==============================================
+//  ********  ******    ********  **********
+//  **///// /**    **  **//////  /**     /**
+//  **      /**    ** /**        /**     /**
+//  ******* /**    ** /********* /**********
+//  **////  /**    ** ////////** /**//////**
+//  **      /**    **        /** /**     /**
+//  **      /**    **  ********  /**     /**
+//  //       /******/  ////////   //      // 
+//
+// FOSA(Frescor Operating System Adaptation layer)
+//================================================
+
+#include "fosa.h"
+
+/**
+ * fosa_eat()
+ *
+ * Eat some time using system clock facilities
+ **/
+void fosa_eat(const fosa_rel_time_t *cpu_time)
+{
+    fosa_clock_id_t clock_id;
+    fosa_abs_time_t current_time, time_to_go;
+
+    // NOTE: there should be a constant for the cpu_clock_id of the caller
+    // to avoid calling 'fosa_thread_get_cputime_clock'
+    fosa_thread_get_cputime_clock(fosa_thread_self(), &clock_id);
+    fosa_clock_get_time(clock_id, &current_time);
+
+    time_to_go = fosa_abs_time_incr(current_time, *cpu_time);
+
+    /* We also spread smaller_timespec */
+    while ( fosa_abs_time_smaller_or_equal(current_time, time_to_go) )
+    {
+        fosa_clock_get_time(clock_id, &current_time);
+    }
+}
+
+
+