From 2e53a2e95e2265c268f38075f551326325bf0b90 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 10 Jul 2007 17:36:33 +0000 Subject: [PATCH] Added test code path which stress tests new thread pool support in OperationsThread --- examples/osgterrain/osgterrain.cpp | 69 ++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index bd1764a9b..f0c78e1c6 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -164,6 +164,7 @@ protected: }; +#if 1 int main(int argc, char** argv) { @@ -436,3 +437,71 @@ int main(int argc, char** argv) return viewer.run(); } + +#else + +#include +#include + +struct MyOperation : public osg::Operation +{ + + MyOperation(const std::string& str, bool keep, double number): + osg::Operation(str,keep), + _number(number) {} + + virtual void operator () (osg::Object* object) + { + OpenThreads::ScopedLock lock(_mutex); + + osg::notify(osg::NOTICE)<add(new MyOperation("two ",true, 0.0)); + + { + typedef std::list< osg::ref_ptr > Threads; + Threads threads; + + unsigned int numberThreads = 2; + while (arguments.read("--threads",numberThreads)) {} + + for(unsigned int i=0; i thread = new osg::OperationsThread; + thread->setOperationQueue(operations.get()); + threads.push_back(thread.get()); + thread->startThread(); + } + + while(!operations->empty()) + { + osg::notify(osg::NOTICE)<<"Main loop"< operation = operations->getNextOperation(); + if (operation.valid()) (*operation)(0); + } + + osg::notify(osg::NOTICE)<<"Completed main loop ******************************* "<