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

PsMultiThreadedController.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 #include "PsMultiThreadedController.h"
00019 
00020 #include "PsnMultiThreadedAsynchronousScheduler.h"
00021 #include "PsnMultiThreadedScheduler.h"
00022 #include "PsConfigurationParameterDescriptor.h"
00023 #include "PsMultipleConfigurationParameter.h"
00024 #include "PsNoRefCountingNameServer.h"
00025 #include "PsnDescriptorMemoryManager.h"
00026 #include "PsnThreadMemoryManager.h"
00027 #include "PsnSystemMemoryManager.h"
00028 
00029 PsMultiThreadedController::PsMultiThreadedController (PsObjectDescriptor & initialObjects,
00030                                                       const PsDate & initialDate,
00031                                                       unsigned int numberOfThreads) : 
00032    PsController(initialObjects,
00033                 initialDate),
00034    _numberOfThreads (numberOfThreads) 
00035 {
00036    //convert the actual name Server to non ref counting name server to avoid contention on the name server locks during ref counting operations
00037    PsNoRefCountingNameServer<STL_ALLOC> * nameServer = new PsNoRefCountingNameServer<STL_ALLOC> (PsName::getNameServer()->getCanonicalRepresentation () ) ;
00038    PsName::setNameServer (nameServer ) ;
00039 }
00040 
00041 PsMultiThreadedController::PsMultiThreadedController (PsObjectDescriptor & initialObjects,
00042                                                       const PsDate & initialDate ) : 
00043    PsController(initialObjects,
00044                 initialDate),
00045    _numberOfThreads (2)
00046 {
00047    //convert the actual name Server to non ref counting name server to avoid contention on the name server locks during ref counting operations
00048    PsNoRefCountingNameServer<STL_ALLOC> * nameServer = new PsNoRefCountingNameServer<STL_ALLOC> (PsName::getNameServer()->getCanonicalRepresentation () ) ;
00049    PsName::setNameServer (nameServer ) ;
00050 
00051    if (getObjectDescriptor().getSchedulingParameters() != NULL )
00052       {
00053          const PsConfigurationParameterDescriptor * param = getObjectDescriptor().getSchedulingParameters()->getSubDescriptorByName("NumberOfThreads") ;
00054          if (param != NULL )
00055             {
00056                _numberOfThreads = atoi (param->getAssociatedString().c_str() ) ; 
00057             }
00058       }
00059    
00060 }
00061 
00062 PsMultiThreadedController::~PsMultiThreadedController() {
00063 
00064 }
00065 
00066 PsnScheduler * PsMultiThreadedController::createScheduler() 
00067 {
00068    return new PsnMultiThreadedScheduler( _nbStepsByCycle , _numberOfThreads, true ) ;
00069 }
00070 
00071 void PsMultiThreadedController::run ()
00072 {
00073     PsnMemoryManager * currentMemoryManager = HeapStackTop::getSystemMemoryManager() ;
00074 
00075    assert ( currentMemoryManager != 0 ) ;
00076 
00077    size_t initialAllocatatedMemory = 1024 * 1024 ;
00078 
00079    void * startMemory = currentMemoryManager->allocateSizeRemembered ( initialAllocatatedMemory ) ;
00080 
00081    PsnDescriptorMemoryManager * descriptorMemoryManager = new PsnDescriptorMemoryManager ( *currentMemoryManager ) ;
00082 
00083    descriptorMemoryManager->init() ;
00084    
00085    PsnThreadMemoryManager * memoryManagerForThisThread ;
00086    
00087    memoryManagerForThisThread = new PsnThreadMemoryManager ( startMemory, 
00088                                                              initialAllocatatedMemory,
00089                                                              *currentMemoryManager,
00090                                                              *descriptorMemoryManager ) ;
00091    memoryManagerForThisThread -> init() ;
00092 
00093    HeapStackTop allocationContextForThisThread ( memoryManagerForThisThread ) ;
00094   
00095    PsController::run() ;
00096 }

logo OpenMask

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

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