]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_partikle/fosa_app_def_sched.c
Updating header text in FOSA files for the incoming final project
[frescor/fosa.git] / src_partikle / fosa_app_def_sched.c
index 057e65606dc2755144e2543cd489caf891c451b2..5d7d0acf91403b32582b809959f3de7e43e0f803 100644 (file)
@@ -1,11 +1,11 @@
 // -----------------------------------------------------------------------
-//  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
+//  Copyright (C) 2006 - 2009 FRESCOR consortium partners:
 //
 //    Universidad de Cantabria,              SPAIN
 //    University of York,                    UK
 //    Scuola Superiore Sant'Anna,            ITALY
 //    Kaiserslautern University,             GERMANY
-//    Univ. Politecnica  Valencia,           SPAIN
+//    Univ. Politécnica  Valencia,           SPAIN
 //    Czech Technical University in Prague,  CZECH REPUBLIC
 //    ENEA                                   SWEDEN
 //    Thales Communication S.A.              FRANCE
 //        The European Union is not liable of any use that may be
 //        made of this code.
 //
-//  This file is part of the FRSH implementation
 //
-//  FRSH is free software; you can  redistribute it and/or  modify
-//  it under the terms of  the GNU General Public License as published by
-//  the Free Software Foundation;  either  version 2, or (at  your option)
-//  any later version.
+//  based on previous work (FSF) done in the FIRST project
 //
-//  FRSH  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.
+//   Copyright (C) 2005  Mälardalen University, SWEDEN
+//                       Scuola Superiore S.Anna, ITALY
+//                       Universidad de Cantabria, SPAIN
+//                       University of York, UK
 //
-//  You should have  received a  copy of  the  GNU  General Public License
-//  distributed  with  FRSH;  see file COPYING.   If not,  write to the
-//  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
-//  02111-1307, USA.
+//   FSF API web pages: http://marte.unican.es/fsf/docs
+//                      http://shark.sssup.it/contrib/first/docs/
 //
-//  As a special exception, if you include this header file into source
-//  files to be compiled, this header file does not by itself cause
-//  the resulting executable 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 General
-//  Public License.
+//   This file is part of FOSA (Frsh Operating System Adaption)
+//
+//  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.
 // -----------------------------------------------------------------------
 //==============================================
 //  ********  ******    ********  **********
@@ -60,6 +68,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>
@@ -99,9 +109,6 @@ void *fosa_scheduler_main (void * args)
        struct posix_appsched_event event;
        struct timespec current_time;
        posix_appsched_eventset_t accepted_events;
-//     bool active;
-       
-       printf ("SCHEDULER thread=0x%lx\n\n", (unsigned long) pthread_self ());
        
        // accept events which have a callback associated
        posix_appsched_fillset (&accepted_events);
@@ -132,9 +139,6 @@ void *fosa_scheduler_main (void * args)
        if (fosa_scheduler_ops.signal)
                posix_appsched_delset (&accepted_events,POSIX_APPSCHED_SIGNAL);
 
-//     if (fosa_scheduler_ops.signal)
-//             posix_appsched_delset (&accepted_events,POSIX_APPSCHED_ERRROR);
-       
        posix_appschedattr_seteventmask(&accepted_events);
        
        // Set the clock (and its) flags used by the scheduler
@@ -146,14 +150,15 @@ void *fosa_scheduler_main (void * args)
        clear_actions (&actions);
 
        while (1) {     // scheduler loop
-//             printf ("ACTIONS: timeout(0x%x), handled_signals=0x%x\n", actions.timeout_ptr, fosa_handled_signals.sig);
                if (posix_appsched_execute_actions(&(actions.actions), &fosa_handled_signals, actions.timeout_ptr,
                    &current_time, &event))
-                       perror ("posix_appsched_execute_actions");
+               {
+                 fosa_scheduler_ops.appsched_error 
+                     (fosa_scheduler_data, 0x0, FOSA_ADS_THREAD_NOT_ATTACHED, &actions);
+                 continue;
+               }
                
-//             printf ("\nReceived event=%d. current_time={%ld,%ld}\n", event.event_code, current_time.tv_sec, current_time.tv_nsec);
                clear_actions (&actions);
-               
                switch (event.event_code) {
                        case POSIX_APPSCHED_NEW:
                                fosa_scheduler_ops.new_thread
@@ -164,12 +169,7 @@ void *fosa_scheduler_main (void * args)
 
                                if (!actions.rejected) {
                                        
-/*                                     active = actions.activated;
-                                       int suspend = actions.suspended; */
-// #ifndef CONFIG_URGENCY  
                                        clear_actions (&actions);
-//                                         printf ("NEW: activate (%d), suspend (%d)\n", actions.activated, actions.suspended);
-// // #endif
   
                                        // alloc memory for reply info of 'fosa_ads_invoke_with_data ()'
                                        struct reply_info *reply_mem = malloc (sizeof (struct reply_info));
@@ -255,16 +255,11 @@ void *fosa_scheduler_main (void * args)
                                                 &actions, 
                                                 &current_time);
                                break;
-
-                       case POSIX_APPSCHED_ERROR:
-                               fosa_scheduler_ops.appsched_error 
-                                       (fosa_scheduler_data, 
-                                        event.thread, 
-                                        0, 
-                                        &actions);
-                               break;
-
 */
+                       default:
+                               printf ("BUG: Unknown ADS event\n");
+                               exit (-20);
+                               break;
                } 
        }
 }
@@ -281,10 +276,6 @@ int fosa_ads_scheduler_create
        pthread_attr_t attr;
        struct sched_param sp;
        
-       
-       printf ("\nMAIN thread=0x%lx\n\n", (unsigned long)pthread_self ());
-       
-       
        if (!scheduler_ops)
                return EINVAL;
        fosa_scheduler_ops = *scheduler_ops;
@@ -469,7 +460,7 @@ int fosa_adsactions_add_activate
        pthread_getschedparam (thread, &policy, &sp);
        fosa_thread_get_prio (thread, &fosaprio);
        sp.sched_priority =  fosa2prtk (fosaprio, urgency);
-       printf ("policy=%d, prio=%d, urg=%d, new_prio=%d\n", policy);
+//     printf ("policy=%d, prio=%d, urg=%d, new_prio=%d\n", policy);
        pthread_setschedparam (thread, policy, &sp);
 #endif
        return posix_appsched_actions_addactivate (&(sched_actions -> actions), thread);
@@ -483,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);