Changeset 430 for experimental/Threading
- Timestamp:
- Oct 25, 2012, 9:49:08 AM (12 years ago)
- Location:
- experimental/Threading/Threading
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/Threading/Threading/IGConnector.cpp
r427 r430 5 5 6 6 7 IGConnector::IGConnector() 7 IGConnector::IGConnector(int numberOfchannels, OpenThreads::Barrier& frameBarrier) 8 : _numberOfchannels(numberOfchannels), _frameBarrier(frameBarrier) 8 9 { 9 10 OSG_ALWAYS<<"IGConnector instantiated."<<std::endl; … … 16 17 void IGConnector::operator()(ThreadedWorker* threadObject) 17 18 { 18 OSG_ALWAYS<<"IGConnector running: ID "<<threadObject->getThreadId()<<std::endl; 19 OSG_ALWAYS<<"IGConnector "<<threadObject->getThreadId()<<" : Receiving SOF packet"<<std::endl; 20 21 _frameBarrier.block(_numberOfchannels+1); // Sync the main and all IG threads. 22 23 OSG_ALWAYS<<"IGConnector "<<threadObject->getThreadId()<<" : Sending SOF answer packet"<<std::endl; 19 24 20 25 // Place Holder -
experimental/Threading/Threading/IGConnector.h
r425 r430 1 1 #pragma once 2 2 #include "ThreadWorkerBase.h" 3 #include <OpenThreads/Barrier> 3 4 4 5 class IGConnector : public ThreadWorkerBase 5 6 { 6 7 public: 7 IGConnector( );8 IGConnector(int numberOfchannels, OpenThreads::Barrier& frameBarrier); 8 9 ~IGConnector(); 9 10 10 11 void operator() (ThreadedWorker* threadObject); 12 13 private: 14 int _numberOfchannels; 15 OpenThreads::Barrier& _frameBarrier; 11 16 }; -
experimental/Threading/Threading/SimHost.cpp
r426 r430 3 3 4 4 #include <OpenThreads/Thread> 5 #include <OpenThreads/Barrier>6 5 7 6 // System includes … … 21 20 { 22 21 OSG_ALWAYS<<"SimHost instantiated."<<std::endl; 22 numberofChannels = 6; 23 23 } 24 24 … … 30 30 void SimHost::initialize() 31 31 { 32 int numThreads = 6+1; // 6 channels and one main thread 32 done = false; 33 int numThreads = numberofChannels+1; // #channels + one main thread 33 34 OpenThreads::Barrier syncBarrier; 34 35 35 36 // Create IG Connectors 36 37 OSG_ALWAYS<<"Creating IG Connectors..."<<std::endl; 37 for(int i=0; i<num Threads-1; ++i)38 for(int i=0; i<numberofChannels; ++i) 38 39 { 39 40 osg::ref_ptr<ThreadedWorker> threadObject = new ThreadedWorker(); 40 osg::ref_ptr<IGConnector> IGCon = new IGConnector( );41 osg::ref_ptr<IGConnector> IGCon = new IGConnector(numberofChannels, _frameBarrier); 41 42 threadObject->setThreadWorker(IGCon); 42 43 _threadObjects.push_back(threadObject); … … 67 68 } 68 69 69 // Do something in the main thread 70 for(int i=0;i<10000000;i++) OSG_ALWAYS<<""; 70 // Enter the SimHost main loop 71 while(!done) 72 { 73 // Wait until all Channels have sent an SOF packet 74 _frameBarrier.block(numberofChannels+1); // Sync the main and all IG threads. 75 OSG_ALWAYS<<"All IGConnectors have recieved a SOF packet: Starting new Frame"<<std::endl; 76 } 71 77 72 78 // Signal threads to finish … … 76 82 _threadObjects[i]->cancel(); // Blocking 77 83 } 78 79 /*for(int i=0;i<100000000;i++)80 OSG_ALWAYS<<"";*/81 82 84 } -
experimental/Threading/Threading/SimHost.h
r425 r430 4 4 #include <osg/Referenced> 5 5 #include <osg/ref_ptr> 6 #include <OpenThreads/Barrier> 6 7 7 8 #include "ThreadedWorker.h" … … 19 20 20 21 private: 22 bool done; 23 int numberofChannels; 24 OpenThreads::Barrier _frameBarrier; 21 25 std::vector<osg::ref_ptr<IGConnector> > _IGConnectors; 22 26 std::vector<osg::ref_ptr<ThreadedWorker> > _threadObjects;
Note: See TracChangeset
for help on using the changeset viewer.