Changeset 3304 for code/trunk/src/core
- Timestamp:
- Jul 18, 2009, 6:23:31 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 12 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/netp6 (added) merged: 3215,3226-3227,3229-3231,3240,3242,3251-3252,3256,3258-3259,3263-3264,3267-3268,3277,3283-3284,3289,3298-3299,3302
- Property svn:mergeinfo changed
-
code/trunk/src/core/CMakeLists.txt
r3280 r3304 61 61 TclBind.cc 62 62 TclThreadManager.cc 63 64 # multithreading 65 Thread.cc 66 ThreadPool.cc 63 67 ) 64 68 ADD_SUBDIRECTORY(input) -
code/trunk/src/core/Clock.cc
r3196 r3304 59 59 tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f; 60 60 61 if (timersTime > 0x 7FFFFFF0)61 if (timersTime > 0xFFFFFFFF/4) 62 62 { 63 63 // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit … … 74 74 unsigned long long Clock::getRealMicroseconds() const 75 75 { 76 return this->timer_->getMicroseconds() ;76 return this->timer_->getMicroseconds() + this->storedTime_; 77 77 } 78 78 } -
code/trunk/src/core/ConsoleCommand.h
r3280 r3304 32 32 #include "CorePrereqs.h" 33 33 34 #include <boost/preprocessor/cat.hpp> 35 34 36 #include "ArgumentCompletionFunctions.h" 35 37 #include "CommandExecutor.h" … … 39 41 40 42 #define SetConsoleCommand(classname, function, bCreateShortcut) \ 41 SetConsoleCommand AliasMulti(classname, function, #function, 0, bCreateShortcut)43 SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut) 42 44 #define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \ 43 SetConsoleCommandAliasMulti(classname, function, name, 0, bCreateShortcut) 44 #define SetConsoleCommandAliasMulti(classname, function, name, number, bCreateShortcut) \ 45 SetConsoleCommandGeneric(classname##function##consolecommand__##number, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut) 45 SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) 46 46 47 #define SetConsoleCommandGeneric( fakevariable, classname, command, bCreateShortcut) \48 orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)47 #define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \ 48 orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut) 49 49 50 50 51 51 #define SetConsoleCommandShortcut(classname, function) \ 52 SetConsoleCommandShortcutAlias Multi(classname, function, #function, 0)52 SetConsoleCommandShortcutAliasGeneric(classname, function, #function) 53 53 #define SetConsoleCommandShortcutAlias(classname, function, name) \ 54 SetConsoleCommandShortcutAlias Multi(classname, function, name, 0)55 #define SetConsoleCommandShortcutAlias Multi(classname, function, name, number) \56 SetConsoleCommandShortcutGeneric( function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))54 SetConsoleCommandShortcutAliasGeneric(classname, function, name) 55 #define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \ 56 SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name)) 57 57 58 58 #define SetConsoleCommandShortcutExtern(function) \ 59 SetConsoleCommandShortcutExternAlias Multi(function, #function, 0)59 SetConsoleCommandShortcutExternAliasGeneric(function, #function) 60 60 #define SetConsoleCommandShortcutExternAlias(function, name) \ 61 SetConsoleCommandShortcutExternAlias Multi(function, name, 0)62 #define SetConsoleCommandShortcutExternAlias Multi(function, name, number) \63 SetConsoleCommandShortcutGeneric( function##consolecommand__##number, orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))61 SetConsoleCommandShortcutExternAliasGeneric(function, name) 62 #define SetConsoleCommandShortcutExternAliasGeneric(function, name) \ 63 SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name)) 64 64 65 65 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ -
code/trunk/src/core/CorePrecompiledHeaders.h
r3214 r3304 60 60 #include <boost/shared_ptr.hpp> // 12 61 61 #include <boost/preprocessor/cat.hpp> // 12 62 // Included by both filesystem and thread but still relatively small63 #include <boost/iterator/iterator_facade.hpp> // 1064 62 65 63 // Just in case some header included windows.h -
code/trunk/src/core/CorePrereqs.h
r3280 r3304 150 150 class SubclassIdentifier; 151 151 class TclBind; 152 struct TclInterpreterBundle;153 152 class TclThreadManager; 154 153 class Template; … … 187 186 class SimpleCommand; 188 187 class SimpleInputState; 188 189 // multithreading 190 class Thread; 191 class ThreadPool; 189 192 } 190 193 … … 197 200 198 201 // Boost 199 namespace boost { namespace filesystem 200 { 201 struct path_traits; 202 template <class String, class Traits> class basic_path; 203 typedef basic_path<std::string, path_traits> path; 204 } } 202 namespace boost 203 { 204 namespace filesystem 205 { 206 struct path_traits; 207 template <class String, class Traits> class basic_path; 208 typedef basic_path<std::string, path_traits> path; 209 } 210 class thread; 211 class mutex; 212 } 205 213 206 214 // TinyXML and TinyXML++ -
code/trunk/src/core/Executor.h
r3301 r3304 246 246 virtual ~ExecutorMember() {} 247 247 248 using Executor::operator(); 249 248 250 inline void operator()(T* object) const 249 251 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } … … 278 280 { ((FunctorMember<T>*)this->functor_)->setObject(object); } 279 281 282 using Executor::parse; 283 280 284 bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const 281 285 { -
code/trunk/src/core/Game.cc
r3300 r3304 40 40 #include "util/Debug.h" 41 41 #include "util/Exception.h" 42 #include "util/Sleep.h" 42 43 #include "util/SubString.h" 43 44 #include "Clock.h" … … 95 96 SetConfigValue(statisticsAvgLength_, 1000000) 96 97 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 98 SetConfigValue(fpsLimit_, 50) 99 .description("Sets the desired framerate (0 for no limit)."); 97 100 } 98 101 99 102 unsigned int statisticsRefreshCycle_; 100 103 unsigned int statisticsAvgLength_; 104 unsigned int fpsLimit_; 101 105 }; 102 106 … … 192 196 193 197 // START GAME 194 this->gameClock_->capture(); // first delta time should be about 0 seconds 198 // first delta time should be about 0 seconds 199 this->gameClock_->capture(); 200 // A first item is required for the fps limiter 201 StatisticsTickInfo tickInfo = {0, 0}; 202 statisticsTickTimes_.push_back(tickInfo); 195 203 while (!this->bAbort_ && (!this->activeStates_.empty() || this->requestedStateNodes_.size() > 0)) 196 204 { 205 uint64_t currentTime = this->gameClock_->getRealMicroseconds(); 206 207 uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + static_cast<uint64_t>(1000000.0f / configuration_->fpsLimit_); 208 if (currentTime < nextTickTime) 209 { 210 usleep(nextTickTime - currentTime); 211 continue; 212 } 197 213 this->gameClock_->capture(); 198 uint64_t currentTime = this->gameClock_->getMicroseconds();199 214 200 215 // STATISTICS -
code/trunk/src/core/IRC.cc
r3301 r3304 47 47 { 48 48 RegisterRootObject(IRC); 49 this-> bundle_ = 0;49 this->interpreter_ = 0; 50 50 } 51 51 … … 54 54 unsigned int threadID = IRC_TCL_THREADID; 55 55 TclThreadManager::createID(threadID); 56 this-> bundle_ = TclThreadManager::getInstance().getInterpreterBundle(threadID);56 this->interpreter_ = TclThreadManager::getInstance().getTclInterpreter(threadID); 57 57 58 58 try 59 59 { 60 this-> bundle_->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic());61 this-> bundle_->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic());62 this-> bundle_->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic());63 this-> bundle_->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic());60 this->interpreter_->def("orxonox::irc::say", IRC::tcl_say, Tcl::variadic()); 61 this->interpreter_->def("orxonox::irc::privmsg", IRC::tcl_privmsg, Tcl::variadic()); 62 this->interpreter_->def("orxonox::irc::action", IRC::tcl_action, Tcl::variadic()); 63 this->interpreter_->def("orxonox::irc::info", IRC::tcl_info, Tcl::variadic()); 64 64 } 65 65 catch (Tcl::tcl_error const &e) … … 81 81 bool IRC::eval(const std::string& command) 82 82 { 83 if (!IRC::getInstance(). bundle_)83 if (!IRC::getInstance().interpreter_) 84 84 { 85 85 IRC::getInstance().initialize(); … … 90 90 try 91 91 { 92 IRC::getInstance(). bundle_->interpreter_->eval(command);92 IRC::getInstance().interpreter_->eval(command); 93 93 return true; 94 94 } -
code/trunk/src/core/IRC.h
r3196 r3304 59 59 ~IRC() {} 60 60 61 Tcl InterpreterBundle* bundle_;61 Tcl::interpreter* interpreter_; 62 62 std::string nickname_; 63 63 }; -
code/trunk/src/core/TclThreadManager.cc
r3301 r3304 30 30 31 31 #include <boost/bind.hpp> 32 #include <boost/thread/condition.hpp> 33 #include <boost/thread/mutex.hpp> 34 #include <boost/thread/thread.hpp> 32 35 #include <OgreTimer.h> 33 36 #include <cpptcl/cpptcl.h> … … 56 59 SetConsoleCommand(TclThreadManager, flush, false).argumentCompleter(0, autocompletion::tclthreads()); 57 60 61 struct TclInterpreterBundle 62 { 63 unsigned int id_; 64 65 std::list<std::string> queue_; 66 boost::mutex queueMutex_; 67 68 Tcl::interpreter* interpreter_; 69 std::string interpreterName_; 70 boost::try_mutex interpreterMutex_; 71 72 std::list<unsigned int> queriers_; 73 boost::mutex queriersMutex_; 74 75 bool running_; 76 boost::mutex runningMutex_; 77 78 bool finished_; 79 boost::mutex finishedMutex_; 80 boost::condition finishedCondition_; 81 }; 82 83 84 static boost::thread::id threadID_g; 85 static boost::mutex bundlesMutex_g; 86 static boost::condition fullQueueCondition_g; 87 static boost::condition orxonoxEvalCondition_g; 88 58 89 TclThreadManager* TclThreadManager::singletonRef_s = 0; 59 90 60 91 TclThreadManager::TclThreadManager(Tcl::interpreter* interpreter) 92 : orxonoxInterpreterBundle_(new TclInterpreterBundle()) 61 93 { 62 94 RegisterRootObject(TclThreadManager); … … 66 98 67 99 this->threadCounter_ = 0; 68 this->orxonoxInterpreterBundle_.id_ = 0; 69 this->orxonoxInterpreterBundle_.interpreter_ = interpreter; 70 #if (BOOST_VERSION >= 103500) 71 this->threadID_ = boost::this_thread::get_id(); 72 #else 73 // 74 #endif 100 this->orxonoxInterpreterBundle_->id_ = 0; 101 this->orxonoxInterpreterBundle_->interpreter_ = interpreter; 102 threadID_g = boost::this_thread::get_id(); 75 103 } 76 104 … … 79 107 unsigned int threadID; 80 108 { 81 boost::mutex::scoped_lock bundles_lock( this->bundlesMutex_);109 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 82 110 if (this->interpreterBundles_.begin() == this->interpreterBundles_.end()) 83 111 return; … … 87 115 this->destroy(threadID); 88 116 117 delete this->orxonoxInterpreterBundle_; 118 89 119 singletonRef_s = 0; 90 120 } … … 92 122 unsigned int TclThreadManager::create() 93 123 { 94 boost::mutex::scoped_lock bundles_lock( TclThreadManager::getInstance().bundlesMutex_);124 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 95 125 TclThreadManager::getInstance().threadCounter_++; 96 126 std::string name = multi_cast<std::string>(TclThreadManager::getInstance().threadCounter_); … … 132 162 if (bundle->finished_) 133 163 { 134 boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_); 135 #if (BOOST_VERSION >= 103500) 164 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 136 165 boost::mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_); 137 #else138 boost::try_mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);139 #endif140 166 try 141 167 { 142 168 while (!interpreter_lock.try_lock()) 143 169 { 144 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one(); 145 #if (BOOST_VERSION >= 103500) 170 orxonoxEvalCondition_g.notify_one(); 146 171 boost::this_thread::yield(); 147 #else148 boost::thread::yield();149 #endif150 172 } 151 173 } catch (...) {} … … 157 179 } 158 180 159 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one(); 160 #if (BOOST_VERSION >= 103500) 181 orxonoxEvalCondition_g.notify_one(); 161 182 boost::this_thread::yield(); 162 #else163 boost::thread::yield();164 #endif165 183 } 166 184 … … 181 199 std::string TclThreadManager::query(unsigned int threadID, const std::string& command) 182 200 { 183 return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_ .id_, threadID, command);201 return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_->id_, threadID, command); 184 202 } 185 203 … … 191 209 output += "\t\t"; 192 210 { 193 boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_ .queueMutex_);194 output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_ .queue_.size());211 boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queueMutex_); 212 output += multi_cast<std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queue_.size()); 195 213 } 196 214 output += "\t\t"; … … 198 216 COUT(0) << output << std::endl; 199 217 200 boost::mutex::scoped_lock bundles_lock( TclThreadManager::getInstance().bundlesMutex_);218 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 201 219 for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it) 202 220 { … … 209 227 output += "\t\t"; 210 228 { 211 #if (BOOST_VERSION >= 103500)212 229 boost::mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_); 213 #else214 boost::try_mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);215 #endif216 230 if (interpreter_lock.try_lock()) 217 231 output += "ready"; … … 228 242 if (threadID == 0) 229 243 { 230 bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;244 bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_; 231 245 COUT(0) << "Queue dump of Orxonox:" << std::endl; 232 246 } … … 254 268 TclInterpreterBundle* bundle = 0; 255 269 if (threadID == 0) 256 bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;270 bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_; 257 271 else 258 272 if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID))) … … 334 348 TclInterpreterBundle* TclThreadManager::getInterpreterBundle(unsigned int threadID) 335 349 { 336 boost::mutex::scoped_lock bundles_lock( this->bundlesMutex_);350 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 337 351 std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.find(threadID); 338 352 if (it != this->interpreterBundles_.end()) … … 347 361 } 348 362 363 Tcl::interpreter* TclThreadManager::getTclInterpreter(unsigned int threadID) 364 { 365 return this->getInterpreterBundle(threadID)->interpreter_; 366 } 367 349 368 std::string TclThreadManager::dumpList(const std::list<unsigned int>& list) 350 369 { … … 362 381 void TclThreadManager::error(const std::string& error) 363 382 { 364 #if (BOOST_VERSION >= 103500) 365 if (boost::this_thread::get_id() != this->threadID_) 366 #else 367 if (boost::thread() != this->threadID_) 368 #endif 369 { 370 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_); 371 if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 372 { 373 #if (BOOST_VERSION >= 103500) 383 if (boost::this_thread::get_id() != threadID_g) 384 { 385 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 386 if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 387 { 374 388 boost::this_thread::yield(); 375 #else376 boost::thread::yield();377 #endif378 389 return; 379 390 } … … 385 396 void TclThreadManager::debug(const std::string& error) 386 397 { 387 #if (BOOST_VERSION >= 103500) 388 if (boost::this_thread::get_id() != this->threadID_) 389 #else 390 if (boost::thread() != this->threadID_) 391 #endif 392 { 393 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_); 394 if (this->orxonoxInterpreterBundle_.queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 395 { 396 #if (BOOST_VERSION >= 103500) 398 if (boost::this_thread::get_id() != threadID_g) 399 { 400 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 401 if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 402 { 397 403 boost::this_thread::yield(); 398 #else399 boost::thread::yield();400 #endif401 404 return; 402 405 } … … 408 411 void TclThreadManager::pushCommandToQueue(const std::string& command) 409 412 { 410 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);411 while (this->orxonoxInterpreterBundle_ .queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)412 this->fullQueueCondition_.wait(queue_lock);413 414 this->orxonoxInterpreterBundle_ .queue_.push_back(command);413 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 414 while (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH) 415 fullQueueCondition_g.wait(queue_lock); 416 417 this->orxonoxInterpreterBundle_->queue_.push_back(command); 415 418 } 416 419 417 420 void TclThreadManager::forceCommandToFrontOfQueue(const std::string& command) 418 421 { 419 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);420 this->orxonoxInterpreterBundle_ .queue_.push_front(command);422 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 423 this->orxonoxInterpreterBundle_->queue_.push_front(command); 421 424 } 422 425 423 426 std::string TclThreadManager::popCommandFromQueue() 424 427 { 425 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);426 std::string temp = this->orxonoxInterpreterBundle_ .queue_.front();427 this->orxonoxInterpreterBundle_ .queue_.pop_front();428 this->fullQueueCondition_.notify_one();428 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 429 std::string temp = this->orxonoxInterpreterBundle_->queue_.front(); 430 this->orxonoxInterpreterBundle_->queue_.pop_front(); 431 fullQueueCondition_g.notify_one(); 429 432 return temp; 430 433 } … … 432 435 bool TclThreadManager::queueIsEmpty() 433 436 { 434 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_ .queueMutex_);435 return this->orxonoxInterpreterBundle_ .queue_.empty();437 boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_); 438 return this->orxonoxInterpreterBundle_->queue_.empty(); 436 439 } 437 440 … … 505 508 if (querier) 506 509 { 507 if (this->updateQueriersList(querier, &this->orxonoxInterpreterBundle_)) 508 { 509 #if (BOOST_VERSION >= 103500) 510 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 511 #else 512 boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 513 #endif 514 this->orxonoxEvalCondition_.wait(interpreter_lock); 510 if (this->updateQueriersList(querier, this->orxonoxInterpreterBundle_)) 511 { 512 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_); 513 orxonoxEvalCondition_g.wait(interpreter_lock); 515 514 516 515 if (!CommandExecutor::execute(command, false)) … … 521 520 } 522 521 523 boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_ .queriersMutex_);524 this->orxonoxInterpreterBundle_ .queriers_.clear();522 boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_->queriersMutex_); 523 this->orxonoxInterpreterBundle_->queriers_.clear(); 525 524 } 526 525 return output; … … 533 532 target = this->getInterpreterBundle(threadID); 534 533 else 535 target = &this->orxonoxInterpreterBundle_;534 target = this->orxonoxInterpreterBundle_; 536 535 537 536 std::string output = ""; … … 542 541 querier = this->getInterpreterBundle(querierID); 543 542 else 544 querier = &this->orxonoxInterpreterBundle_;543 querier = this->orxonoxInterpreterBundle_; 545 544 546 545 if (querier) … … 548 547 if (this->updateQueriersList(querier, target)) 549 548 { 550 #if (BOOST_VERSION >= 103500)551 549 boost::mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_); 552 #else553 boost::try_mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);554 #endif555 550 bool successfullyLocked = false; 556 551 try … … 562 557 while (!interpreter_lock.try_lock()) 563 558 { 564 #if (BOOST_VERSION >= 103500)565 559 boost::this_thread::yield(); 566 #else567 boost::thread::yield();568 #endif569 560 } 570 561 … … 599 590 { 600 591 { 601 this->orxonoxEvalCondition_.notify_one(); 602 #if (BOOST_VERSION >= 103500) 592 orxonoxEvalCondition_g.notify_one(); 603 593 boost::this_thread::yield(); 604 #else 605 boost::thread::yield(); 606 #endif 607 } 608 609 { 610 boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_); 594 } 595 596 { 597 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 611 598 for (std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it) 612 599 { … … 626 613 627 614 { 628 #if (BOOST_VERSION >= 103500) 629 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 630 #else 631 boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_); 632 #endif 615 boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_); 633 616 unsigned long maxtime = static_cast<unsigned long>(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE); 634 617 Ogre::Timer timer; … … 644 627 std::list<unsigned int> TclThreadManager::getThreadList() const 645 628 { 646 boost::mutex::scoped_lock bundles_lock( TclThreadManager::getInstance().bundlesMutex_);629 boost::mutex::scoped_lock bundles_lock(bundlesMutex_g); 647 630 std::list<unsigned int> threads; 648 631 for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it) … … 654 637 { 655 638 TclThreadManager::getInstance().debug("TclThread_execute: " + command); 656 #if (BOOST_VERSION >= 103500)657 639 boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_); 658 #else659 boost::try_mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);660 #endif661 640 try 662 641 { -
code/trunk/src/core/TclThreadManager.h
r3196 r3304 32 32 #include "CorePrereqs.h" 33 33 34 #include <cassert> 34 35 #include <list> 35 36 #include <map> 36 37 #include <string> 37 #include <boost/thread/condition.hpp>38 #include <boost/thread/mutex.hpp>39 #include <boost/thread/thread.hpp>40 41 38 #include "core/OrxonoxClass.h" 42 39 43 40 namespace orxonox 44 41 { 45 struct _CoreExport TclInterpreterBundle 46 { 47 unsigned int id_; 48 49 std::list<std::string> queue_; 50 boost::mutex queueMutex_; 51 52 Tcl::interpreter* interpreter_; 53 std::string interpreterName_; 54 boost::try_mutex interpreterMutex_; 55 56 std::list<unsigned int> queriers_; 57 boost::mutex queriersMutex_; 58 59 bool running_; 60 boost::mutex runningMutex_; 61 62 bool finished_; 63 boost::mutex finishedMutex_; 64 boost::condition finishedCondition_; 65 }; 42 // Internal struct 43 struct TclInterpreterBundle; 66 44 67 45 class _CoreExport TclThreadManager : public OrxonoxClass … … 101 79 102 80 Tcl::interpreter* createNewTclInterpreter(const std::string& threadID); 81 Tcl::interpreter* getTclInterpreter(unsigned int threadID); 103 82 TclInterpreterBundle* getInterpreterBundle(unsigned int threadID); 104 83 std::string dumpList(const std::list<unsigned int>& list); … … 119 98 120 99 unsigned int threadCounter_; 121 TclInterpreterBundle orxonoxInterpreterBundle_;100 TclInterpreterBundle* orxonoxInterpreterBundle_; 122 101 std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_; 123 boost::mutex bundlesMutex_;124 boost::condition fullQueueCondition_;125 boost::condition orxonoxEvalCondition_;126 #if (BOOST_VERSION >= 103500)127 boost::thread::id threadID_;128 #else129 boost::thread threadID_;130 #endif131 102 132 103 static TclThreadManager* singletonRef_s;
Note: See TracChangeset
for help on using the changeset viewer.