Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsRealTimeController.cxx

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *  
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license
00016  *
00017  */
00018 #ifdef _SGI
00019 #include <PsRealTimeController.h>
00020 #include <sys/time.h>
00021 #include <sys/syssgi.h>
00022 #include <unistd.h>
00023 
00024 // PsController::PsController
00025 //--------------------------------------------------------
00026 
00027 PsRealTimeController::PsRealTimeController(PsObjectDescriptor & scenario, const PsDate & initialDate) 
00028 :  PsController(scenario, initialDate)
00029 {
00030 }
00031 
00032 //----------------------------------------------------------
00033 // destructeur
00034 
00035 PsRealTimeController::~PsRealTimeController() {
00036 }
00037 
00038 void PsRealTimeController::compute (){
00039    static long avance = 0 ;
00040    static timespec avant, apres;
00041 
00042    clock_gettime(CLOCK_SGI_CYCLE, &avant);
00043 
00044    PsController::compute ();
00045 
00046    //lecture des compteurs du pas de calcul
00047    clock_gettime(CLOCK_SGI_CYCLE, &apres);
00048 
00049    long duree = apres.tv_nsec - avant.tv_nsec ;
00050    if (duree < 0 ) duree =  apres.tv_nsec + ( LONG_MAX/2 - avant.tv_nsec ) ;
00051 
00052    //Les 4 lignes qui suivent sont une tentative primitive d'atteinte du temps réel
00053    avance += _stepPeriod * 1000  - duree / 1000 ;
00054    if (avance > 10000) {
00055       usleep( avance );
00056       clock_gettime(CLOCK_SGI_CYCLE, &apres);
00057       if (apres.tv_nsec > avant.tv_nsec) {
00058          avance = avance - (apres.tv_nsec - avant.tv_nsec) / 1000 ;
00059       }
00060       else {
00061          avance =  avance - (( LONG_MAX/2 - avant.tv_nsec ) + apres.tv_nsec ) / 1000 ;
00062       }
00063    }
00064 }
00065 #endif
00066 
00067 
00068 
00069 
00070 

logo OpenMask

Documentation generated on Mon Nov 25 15:25:02 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001