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

PsnMultiThreadedAsynchronousScheduler Class Reference

class PsnMultiThreadedAsynchronousScheduler (experimetal) : use threads to schedule the different simulation objects. More...

#include <PsnMultiThreadedAsynchronousScheduler.h>

Inheritance diagram for PsnMultiThreadedAsynchronousScheduler:

Inheritance graph
[legend]
Collaboration diagram for PsnMultiThreadedAsynchronousScheduler:

Collaboration graph
[legend]
List of all members.

Public Methods

 PsnMultiThreadedAsynchronousScheduler (unsigned int numberOfSteps, unsigned int numberOfThreads)
virtual ~PsnMultiThreadedAsynchronousScheduler ()
virtual void addToScheduable (PsnReferenceObjectHandle *ref, unsigned int when)
 redefine so that simulated objects are assigned to threads in a cyclic manner

virtual void removeFromScheduable (PsnReferenceObjectHandle *ref)
 redefine to remove the simulated object from schedulers local to a thread

virtual void schedule (PsnReferenceObjectHandle *ref)
 mark a scheduable object as active

virtual void unschedule (PsnReferenceObjectHandle *ref)
 mark a scheduable object as inactive

virtual void runStep (unsigned int which)
 run a simulation step

virtual void runAsynchronous ()

Static Protected Methods

void * _asynchronousThreadContainer (void *)

Protected Attributes

PsnMutexLock _runDataAccess
bool _running
bool _started
PsnCondition _runCondition
PsnReferenceObjectHandle_asyncRef
PsName _nameOfAsynchronousObject
pthread_t _asynchronousThreadId

Detailed Description

class PsnMultiThreadedAsynchronousScheduler (experimetal) : use threads to schedule the different simulation objects.

This scheduler is able to schedule asynchronous threads with respect to the simulation.

Author:
David Margery
Version:
:

Definition at line 33 of file PsnMultiThreadedAsynchronousScheduler.h.


Constructor & Destructor Documentation

PsnMultiThreadedAsynchronousScheduler::PsnMultiThreadedAsynchronousScheduler unsigned int    numberOfSteps,
unsigned int    numberOfThreads
 

Definition at line 26 of file PsnMultiThreadedAsynchronousScheduler.cxx.

00027                                                                                                                  :
00028    PsnMultiThreadedScheduler(numberOfSteps, numberOfThreads,true),
00029    _running (false),
00030    _started (false),
00031    _nameOfAsynchronousObject("visu")
00032 {
00033    cerr<<"Warning : using a experimental scheduler. UNSUPPORTED"<<endl;
00034    cerr<<"Only supports ONE asynchronous object"<<endl;
00035 }

PsnMultiThreadedAsynchronousScheduler::~PsnMultiThreadedAsynchronousScheduler   [virtual]
 

Definition at line 37 of file PsnMultiThreadedAsynchronousScheduler.cxx.

00037                                                                               {
00038 }


Member Function Documentation

void * PsnMultiThreadedAsynchronousScheduler::_asynchronousThreadContainer void *    [static, protected]
 

Definition at line 111 of file PsnMultiThreadedAsynchronousScheduler.cxx.

References runAsynchronous().

Referenced by addToScheduable().

00111                                                                                                 {
00112    PsnMultiThreadedAsynchronousScheduler * scheduler = (PsnMultiThreadedAsynchronousScheduler *) theScheduler ;
00113 
00114    scheduler->runAsynchronous() ;
00115 
00116    return scheduler ;
00117 }

void PsnMultiThreadedAsynchronousScheduler::addToScheduable PsnReferenceObjectHandle   ref,
unsigned int    when
[virtual]
 

redefine so that simulated objects are assigned to threads in a cyclic manner

Reimplemented from PsnMultiThreadedScheduler.

Definition at line 40 of file PsnMultiThreadedAsynchronousScheduler.cxx.

References _asynchronousThreadContainer(), _asynchronousThreadId, _asyncRef, _nameOfAsynchronousObject, PsnMultiThreadedScheduler::addToScheduable(), PsController::error(), PsObjectDescriptor::getName(), PsSimulatedObject::getObjectDescriptor(), PsnObjectHandle::getSimulatedObject(), PsnReferenceObjectHandle::running, and PsnScheduler::setComputingState().

00040                                                                                                               {
00041    if (ref->getSimulatedObject().getObjectDescriptor().getName() == _nameOfAsynchronousObject) {
00042       _asyncRef = ref ;
00043       setComputingState (ref,PsnReferenceObjectHandle::running ) ; 
00044       int ret = pthread_create(&_asynchronousThreadId,
00045                                0,
00046                                (void *(*)(void *))_asynchronousThreadContainer,
00047                                this) ;
00048        if (ret) {
00049          PsController::error("Couldn't create asynchronous thread") ;
00050       }
00051    }
00052    else {
00053       PsnMultiThreadedScheduler::addToScheduable ( ref , when );
00054    }
00055 }

void PsnMultiThreadedAsynchronousScheduler::removeFromScheduable PsnReferenceObjectHandle   ref [virtual]
 

redefine to remove the simulated object from schedulers local to a thread

Reimplemented from PsnMultiThreadedScheduler.

Definition at line 59 of file PsnMultiThreadedAsynchronousScheduler.cxx.

References _asyncRef, and PsnMultiThreadedScheduler::removeFromScheduable().

00059                                                                                                 {
00060    if ( ref == _asyncRef ) {
00061       //nothing to do : the asynchronous thread has been stopped. destroying it would be to painfull code to write ! 
00062    }
00063    else {
00064       PsnMultiThreadedScheduler::removeFromScheduable ( ref );
00065    }
00066 } ;

void PsnMultiThreadedAsynchronousScheduler::runAsynchronous   [virtual]
 

Definition at line 121 of file PsnMultiThreadedAsynchronousScheduler.cxx.

References _runCondition, _runDataAccess, _running, _started, PsnMutexLock::protect(), PsnCondition::signalChange(), PsnMutexLock::unprotect(), and PsnCondition::waitForChange().

Referenced by _asynchronousThreadContainer().

00121                                                             {
00122    bool init = false ;
00123    _runDataAccess.protect() ;
00124    while (!_started) {
00125          _runDataAccess.unprotect() ;
00126          _runCondition.waitForChange( _runDataAccess ) ;
00127    }
00128    
00129    _runDataAccess.unprotect() ;
00130 
00131    assert (false ) ;
00132    //_asyncRef->getSimulatedObject().init() ;
00133    
00134    while (true) {
00135       _runDataAccess.protect() ;
00136 
00137       while (!(_running && _started) ) {
00138          _runDataAccess.unprotect() ;
00139          _runCondition.waitForChange( _runDataAccess ) ;
00140          
00141       }
00142 
00143       _runDataAccess.unprotect() ;   
00144 
00145       try {
00146 
00147          assert (false) ;
00148          //_asyncRef->getSimulatedObject().compute() ;
00149 
00150       }
00151       catch (PsUnInitialisedAttributeException & e) {
00152          _runDataAccess.protect() ;
00153          _started = false ;
00154          _runDataAccess.unprotect() ;
00155          _runCondition.signalChange() ;
00156       }
00157    }
00158 }

void PsnMultiThreadedAsynchronousScheduler::runStep unsigned int    which [virtual]
 

run a simulation step

Reimplemented from PsnMultiThreadedScheduler.

Definition at line 96 of file PsnMultiThreadedAsynchronousScheduler.cxx.

References _runCondition, _runDataAccess, _started, PsnMutexLock::protect(), PsnMultiThreadedScheduler::runStep(), PsnCondition::signalChange(), and PsnMutexLock::unprotect().

00096                                                                        {
00097    _runDataAccess.protect() ;
00098    if (!_started) {
00099       _started = true ;
00100       _runDataAccess.unprotect() ;
00101       _runCondition.signalChange() ;
00102    }
00103    else {
00104       _runDataAccess.unprotect() ;      
00105    }
00106    PsnMultiThreadedScheduler::runStep( which ) ;
00107 }

void PsnMultiThreadedAsynchronousScheduler::schedule PsnReferenceObjectHandle   ref [virtual]
 

mark a scheduable object as active

Reimplemented from PsnMultiThreadedScheduler.

Definition at line 70 of file PsnMultiThreadedAsynchronousScheduler.cxx.

References _asyncRef, _runCondition, _runDataAccess, _running, PsnMutexLock::protect(), PsnMultiThreadedScheduler::schedule(), PsnCondition::signalChange(), and PsnMutexLock::unprotect().

00070                                                                                    {
00071    if ( ref == _asyncRef ) {
00072       _runDataAccess.protect() ;
00073       _running = true ;
00074       _runDataAccess.unprotect () ;
00075       _runCondition.signalChange() ;
00076    }
00077    else {
00078       PsnMultiThreadedScheduler::schedule ( ref );
00079    }
00080 }

void PsnMultiThreadedAsynchronousScheduler::unschedule PsnReferenceObjectHandle   ref [virtual]
 

mark a scheduable object as inactive

Reimplemented from PsnMultiThreadedScheduler.

Definition at line 84 of file PsnMultiThreadedAsynchronousScheduler.cxx.

References _asyncRef, _runCondition, _runDataAccess, _running, PsnMutexLock::protect(), PsnCondition::signalChange(), PsnMutexLock::unprotect(), and PsnMultiThreadedScheduler::unschedule().

00084                                                                                      {
00085    if ( ref == _asyncRef ) {
00086       _runDataAccess.protect () ;
00087       _running = false ;
00088       _runDataAccess.unprotect () ;
00089       _runCondition.signalChange() ;
00090    }
00091    else {
00092       PsnMultiThreadedScheduler::unschedule ( ref );
00093    }
00094 }


Member Data Documentation

pthread_t PsnMultiThreadedAsynchronousScheduler::_asynchronousThreadId [protected]
 

Definition at line 56 of file PsnMultiThreadedAsynchronousScheduler.h.

Referenced by addToScheduable().

PsnReferenceObjectHandle* PsnMultiThreadedAsynchronousScheduler::_asyncRef [protected]
 

Definition at line 54 of file PsnMultiThreadedAsynchronousScheduler.h.

Referenced by addToScheduable(), removeFromScheduable(), schedule(), and unschedule().

PsName PsnMultiThreadedAsynchronousScheduler::_nameOfAsynchronousObject [protected]
 

Definition at line 55 of file PsnMultiThreadedAsynchronousScheduler.h.

Referenced by addToScheduable().

PsnCondition PsnMultiThreadedAsynchronousScheduler::_runCondition [protected]
 

Definition at line 53 of file PsnMultiThreadedAsynchronousScheduler.h.

Referenced by runAsynchronous(), runStep(), schedule(), and unschedule().

PsnMutexLock PsnMultiThreadedAsynchronousScheduler::_runDataAccess [protected]
 

Definition at line 50 of file PsnMultiThreadedAsynchronousScheduler.h.

Referenced by runAsynchronous(), runStep(), schedule(), and unschedule().

bool PsnMultiThreadedAsynchronousScheduler::_running [protected]
 

Definition at line 51 of file PsnMultiThreadedAsynchronousScheduler.h.

Referenced by runAsynchronous(), schedule(), and unschedule().

bool PsnMultiThreadedAsynchronousScheduler::_started [protected]
 

Definition at line 52 of file PsnMultiThreadedAsynchronousScheduler.h.

Referenced by runAsynchronous(), and runStep().


The documentation for this class was generated from the following files:
logo OpenMask

Documentation generated on Mon Nov 25 15:26:11 2002

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