Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3304 for code/trunk/src/core


Ignore:
Timestamp:
Jul 18, 2009, 6:23:31 PM (15 years ago)
Author:
rgrieder
Message:

Merged netp6 branch back to the trunk.

Location:
code/trunk
Files:
12 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/CMakeLists.txt

    r3280 r3304  
    6161  TclBind.cc
    6262  TclThreadManager.cc
     63 
     64  # multithreading
     65  Thread.cc
     66  ThreadPool.cc
    6367)
    6468ADD_SUBDIRECTORY(input)
  • code/trunk/src/core/Clock.cc

    r3196 r3304  
    5959        tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
    6060
    61         if (timersTime > 0x7FFFFFF0)
     61        if (timersTime > 0xFFFFFFFF/4)
    6262        {
    6363            // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
     
    7474    unsigned long long Clock::getRealMicroseconds() const
    7575    {
    76         return this->timer_->getMicroseconds();
     76        return this->timer_->getMicroseconds() + this->storedTime_;
    7777    }
    7878}
  • code/trunk/src/core/ConsoleCommand.h

    r3280 r3304  
    3232#include "CorePrereqs.h"
    3333
     34#include <boost/preprocessor/cat.hpp>
     35
    3436#include "ArgumentCompletionFunctions.h"
    3537#include "CommandExecutor.h"
     
    3941
    4042#define SetConsoleCommand(classname, function, bCreateShortcut) \
    41     SetConsoleCommandAliasMulti(classname, function, #function, 0, bCreateShortcut)
     43    SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut)
    4244#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)
    4646
    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)
    4949
    5050
    5151#define SetConsoleCommandShortcut(classname, function) \
    52     SetConsoleCommandShortcutAliasMulti(classname, function, #function, 0)
     52    SetConsoleCommandShortcutAliasGeneric(classname, function, #function)
    5353#define SetConsoleCommandShortcutAlias(classname, function, name) \
    54     SetConsoleCommandShortcutAliasMulti(classname, function, name, 0)
    55 #define SetConsoleCommandShortcutAliasMulti(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))
    5757
    5858#define SetConsoleCommandShortcutExtern(function) \
    59     SetConsoleCommandShortcutExternAliasMulti(function, #function, 0)
     59    SetConsoleCommandShortcutExternAliasGeneric(function, #function)
    6060#define SetConsoleCommandShortcutExternAlias(function, name) \
    61     SetConsoleCommandShortcutExternAliasMulti(function, name, 0)
    62 #define SetConsoleCommandShortcutExternAliasMulti(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))
    6464
    6565#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
  • code/trunk/src/core/CorePrecompiledHeaders.h

    r3214 r3304  
    6060#include <boost/shared_ptr.hpp> // 12
    6161#include <boost/preprocessor/cat.hpp> // 12
    62 // Included by both filesystem and thread but still relatively small
    63 #include <boost/iterator/iterator_facade.hpp> // 10
    6462
    6563// Just in case some header included windows.h
  • code/trunk/src/core/CorePrereqs.h

    r3280 r3304  
    150150    class SubclassIdentifier;
    151151    class TclBind;
    152     struct TclInterpreterBundle;
    153152    class TclThreadManager;
    154153    class Template;
     
    187186    class SimpleCommand;
    188187    class SimpleInputState;
     188
     189    // multithreading
     190    class Thread;
     191    class ThreadPool;
    189192}
    190193
     
    197200
    198201// 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 } }
     202namespace 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}
    205213
    206214// TinyXML and TinyXML++
  • code/trunk/src/core/Executor.h

    r3301 r3304  
    246246            virtual ~ExecutorMember() {}
    247247
     248            using Executor::operator();
     249
    248250            inline void operator()(T* object) const
    249251                { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     
    278280                { ((FunctorMember<T>*)this->functor_)->setObject(object); }
    279281
     282            using Executor::parse;
     283
    280284            bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
    281285            {
  • code/trunk/src/core/Game.cc

    r3300 r3304  
    4040#include "util/Debug.h"
    4141#include "util/Exception.h"
     42#include "util/Sleep.h"
    4243#include "util/SubString.h"
    4344#include "Clock.h"
     
    9596            SetConfigValue(statisticsAvgLength_, 1000000)
    9697                .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).");
    97100        }
    98101
    99102        unsigned int statisticsRefreshCycle_;
    100103        unsigned int statisticsAvgLength_;
     104        unsigned int fpsLimit_;
    101105    };
    102106
     
    192196
    193197        // 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);
    195203        while (!this->bAbort_ && (!this->activeStates_.empty() || this->requestedStateNodes_.size() > 0))
    196204        {
     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            }
    197213            this->gameClock_->capture();
    198             uint64_t currentTime = this->gameClock_->getMicroseconds();
    199214
    200215            // STATISTICS
  • code/trunk/src/core/IRC.cc

    r3301 r3304  
    4747    {
    4848        RegisterRootObject(IRC);
    49         this->bundle_ = 0;
     49        this->interpreter_ = 0;
    5050    }
    5151
     
    5454        unsigned int threadID = IRC_TCL_THREADID;
    5555        TclThreadManager::createID(threadID);
    56         this->bundle_ = TclThreadManager::getInstance().getInterpreterBundle(threadID);
     56        this->interpreter_ = TclThreadManager::getInstance().getTclInterpreter(threadID);
    5757
    5858        try
    5959        {
    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());
    6464        }
    6565        catch (Tcl::tcl_error const &e)
     
    8181    bool IRC::eval(const std::string& command)
    8282    {
    83         if (!IRC::getInstance().bundle_)
     83        if (!IRC::getInstance().interpreter_)
    8484        {
    8585            IRC::getInstance().initialize();
     
    9090        try
    9191        {
    92             IRC::getInstance().bundle_->interpreter_->eval(command);
     92            IRC::getInstance().interpreter_->eval(command);
    9393            return true;
    9494        }
  • code/trunk/src/core/IRC.h

    r3196 r3304  
    5959            ~IRC() {}
    6060
    61             TclInterpreterBundle* bundle_;
     61            Tcl::interpreter* interpreter_;
    6262            std::string nickname_;
    6363    };
  • code/trunk/src/core/TclThreadManager.cc

    r3301 r3304  
    3030
    3131#include <boost/bind.hpp>
     32#include <boost/thread/condition.hpp>
     33#include <boost/thread/mutex.hpp>
     34#include <boost/thread/thread.hpp>
    3235#include <OgreTimer.h>
    3336#include <cpptcl/cpptcl.h>
     
    5659    SetConsoleCommand(TclThreadManager, flush,   false).argumentCompleter(0, autocompletion::tclthreads());
    5760
     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
    5889    TclThreadManager* TclThreadManager::singletonRef_s = 0;
    5990
    6091    TclThreadManager::TclThreadManager(Tcl::interpreter* interpreter)
     92        : orxonoxInterpreterBundle_(new TclInterpreterBundle())
    6193    {
    6294        RegisterRootObject(TclThreadManager);
     
    6698
    6799        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();
    75103    }
    76104
     
    79107        unsigned int threadID;
    80108        {
    81             boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     109            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    82110            if (this->interpreterBundles_.begin() == this->interpreterBundles_.end())
    83111                return;
     
    87115        this->destroy(threadID);
    88116
     117        delete this->orxonoxInterpreterBundle_;
     118
    89119        singletonRef_s = 0;
    90120    }
     
    92122    unsigned int TclThreadManager::create()
    93123    {
    94         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     124        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    95125        TclThreadManager::getInstance().threadCounter_++;
    96126        std::string name = multi_cast<std::string>(TclThreadManager::getInstance().threadCounter_);
     
    132162                    if (bundle->finished_)
    133163                    {
    134                         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
    135 #if (BOOST_VERSION >= 103500)
     164                        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    136165                        boost::mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
    137 #else
    138                         boost::try_mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
    139 #endif
    140166                        try
    141167                        {
    142168                            while (!interpreter_lock.try_lock())
    143169                            {
    144                                 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
    145 #if (BOOST_VERSION >= 103500)
     170                                orxonoxEvalCondition_g.notify_one();
    146171                                boost::this_thread::yield();
    147 #else
    148                                 boost::thread::yield();
    149 #endif
    150172                            }
    151173                        } catch (...) {}
     
    157179                }
    158180
    159                 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
    160 #if (BOOST_VERSION >= 103500)
     181                orxonoxEvalCondition_g.notify_one();
    161182                boost::this_thread::yield();
    162 #else
    163                 boost::thread::yield();
    164 #endif
    165183            }
    166184
     
    181199    std::string TclThreadManager::query(unsigned int threadID, const std::string& command)
    182200    {
    183         return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_.id_, threadID, command);
     201        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_->id_, threadID, command);
    184202    }
    185203
     
    191209        output += "\t\t";
    192210        {
    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());
    195213        }
    196214        output += "\t\t";
     
    198216        COUT(0) << output << std::endl;
    199217
    200         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     218        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    201219        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it)
    202220        {
     
    209227            output += "\t\t";
    210228            {
    211 #if (BOOST_VERSION >= 103500)
    212229                boost::mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
    213 #else
    214                 boost::try_mutex::scoped_try_lock interpreter_lock((*it).second->interpreterMutex_);
    215 #endif
    216230                if (interpreter_lock.try_lock())
    217231                    output += "ready";
     
    228242        if (threadID == 0)
    229243        {
    230             bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     244            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
    231245            COUT(0) << "Queue dump of Orxonox:" << std::endl;
    232246        }
     
    254268        TclInterpreterBundle* bundle = 0;
    255269        if (threadID == 0)
    256             bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     270            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
    257271        else
    258272            if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID)))
     
    334348    TclInterpreterBundle* TclThreadManager::getInterpreterBundle(unsigned int threadID)
    335349    {
    336         boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     350        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    337351        std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.find(threadID);
    338352        if (it != this->interpreterBundles_.end())
     
    347361    }
    348362
     363    Tcl::interpreter* TclThreadManager::getTclInterpreter(unsigned int threadID)
     364    {
     365        return this->getInterpreterBundle(threadID)->interpreter_;
     366    }
     367
    349368    std::string TclThreadManager::dumpList(const std::list<unsigned int>& list)
    350369    {
     
    362381    void TclThreadManager::error(const std::string& error)
    363382    {
    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            {
    374388                boost::this_thread::yield();
    375 #else
    376                 boost::thread::yield();
    377 #endif
    378389                return;
    379390            }
     
    385396    void TclThreadManager::debug(const std::string& error)
    386397    {
    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            {
    397403                boost::this_thread::yield();
    398 #else
    399                 boost::thread::yield();
    400 #endif
    401404                return;
    402405            }
     
    408411    void TclThreadManager::pushCommandToQueue(const std::string& command)
    409412    {
    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);
    415418    }
    416419
    417420    void TclThreadManager::forceCommandToFrontOfQueue(const std::string& command)
    418421    {
    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);
    421424    }
    422425
    423426    std::string TclThreadManager::popCommandFromQueue()
    424427    {
    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();
    429432        return temp;
    430433    }
     
    432435    bool TclThreadManager::queueIsEmpty()
    433436    {
    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();
    436439    }
    437440
     
    505508        if (querier)
    506509        {
    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);
    515514
    516515                if (!CommandExecutor::execute(command, false))
     
    521520            }
    522521
    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();
    525524        }
    526525        return output;
     
    533532            target = this->getInterpreterBundle(threadID);
    534533        else
    535             target = &this->orxonoxInterpreterBundle_;
     534            target = this->orxonoxInterpreterBundle_;
    536535
    537536        std::string output = "";
     
    542541                querier = this->getInterpreterBundle(querierID);
    543542            else
    544                 querier = &this->orxonoxInterpreterBundle_;
     543                querier = this->orxonoxInterpreterBundle_;
    545544
    546545            if (querier)
     
    548547                if (this->updateQueriersList(querier, target))
    549548                {
    550 #if (BOOST_VERSION >= 103500)
    551549                    boost::mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
    552 #else
    553                     boost::try_mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
    554 #endif
    555550                    bool successfullyLocked = false;
    556551                    try
     
    562557                            while (!interpreter_lock.try_lock())
    563558                            {
    564 #if (BOOST_VERSION >= 103500)
    565559                                boost::this_thread::yield();
    566 #else
    567                                 boost::thread::yield();
    568 #endif
    569560                            }
    570561
     
    599590    {
    600591        {
    601             this->orxonoxEvalCondition_.notify_one();
    602 #if (BOOST_VERSION >= 103500)
     592            orxonoxEvalCondition_g.notify_one();
    603593            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);
    611598            for (std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
    612599            {
     
    626613
    627614        {
    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_);
    633616            unsigned long maxtime = static_cast<unsigned long>(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE);
    634617            Ogre::Timer timer;
     
    644627    std::list<unsigned int> TclThreadManager::getThreadList() const
    645628    {
    646         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     629        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    647630        std::list<unsigned int> threads;
    648631        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
     
    654637    {
    655638        TclThreadManager::getInstance().debug("TclThread_execute: " + command);
    656 #if (BOOST_VERSION >= 103500)
    657639        boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
    658 #else
    659         boost::try_mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
    660 #endif
    661640        try
    662641        {
  • code/trunk/src/core/TclThreadManager.h

    r3196 r3304  
    3232#include "CorePrereqs.h"
    3333
     34#include <cassert>
    3435#include <list>
    3536#include <map>
    3637#include <string>
    37 #include <boost/thread/condition.hpp>
    38 #include <boost/thread/mutex.hpp>
    39 #include <boost/thread/thread.hpp>
    40 
    4138#include "core/OrxonoxClass.h"
    4239
    4340namespace orxonox
    4441{
    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;
    6644
    6745    class _CoreExport TclThreadManager : public OrxonoxClass
     
    10179
    10280            Tcl::interpreter* createNewTclInterpreter(const std::string& threadID);
     81            Tcl::interpreter* getTclInterpreter(unsigned int threadID);
    10382            TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
    10483            std::string dumpList(const std::list<unsigned int>& list);
     
    11998
    12099            unsigned int threadCounter_;
    121             TclInterpreterBundle orxonoxInterpreterBundle_;
     100            TclInterpreterBundle* orxonoxInterpreterBundle_;
    122101            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 #else
    129             boost::thread threadID_;
    130 #endif
    131102
    132103            static TclThreadManager* singletonRef_s;
Note: See TracChangeset for help on using the changeset viewer.