Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3264 for code/branches/netp6


Ignore:
Timestamp:
Jul 1, 2009, 11:22:03 AM (15 years ago)
Author:
rgrieder
Message:

Moved boost headers from TclThreadmanager.h to the source file.
Also removed the old boost 1.34 commands since Oli requires 1.35 anyway and there have been about three or four new releases of boost since the writing of the code.

Location:
code/branches/netp6/src/core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp6/src/core/CorePrecompiledHeaders.h

    r3214 r3264  
    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/branches/netp6/src/core/CorePrereqs.h

    r3240 r3264  
    150150    class SubclassIdentifier;
    151151    class TclBind;
    152     struct TclInterpreterBundle;
    153152    class TclThreadManager;
    154153    class Template;
     
    207206        template <class String, class Traits> class basic_path;
    208207        typedef basic_path<std::string, path_traits> path;
    209     } 
     208    }
    210209    class thread;
    211210    class mutex;
  • code/branches/netp6/src/core/IRC.cc

    r3196 r3264  
    4747    {
    4848        RegisterRootObject(IRC);
    49         this->bundle_ = 0;
     49        this->interpreter_ = 0;
    5050    }
    5151
     
    5454        unsigned int threadID = (unsigned int)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)
     
    6868        {   COUT(1) << "Error while initializing Tcl (IRC): " << e.what();   }
    6969
    70         this->nickname_ = "orx" + getConvertedValue<int, std::string>((unsigned int)rand());
     70        this->nickname_ = "orx" + getConvertedValue<int, std::string>(static_cast<unsigned int>(rand()));
    7171        TclThreadManager::execute(threadID, "set nickname " + this->nickname_);
    7272        TclThreadManager::execute(threadID, "source irc.tcl");
     
    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/branches/netp6/src/core/IRC.h

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

    r3196 r3264  
    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
     
    6697
    6798        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
     99        this->orxonoxInterpreterBundle_->id_ = 0;
     100        this->orxonoxInterpreterBundle_->interpreter_ = interpreter;
     101        threadID_g = boost::this_thread::get_id();
    75102    }
    76103
     
    79106        unsigned int threadID;
    80107        {
    81             boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     108            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    82109            if (this->interpreterBundles_.begin() == this->interpreterBundles_.end())
    83110                return;
     
    92119    unsigned int TclThreadManager::create()
    93120    {
    94         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     121        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    95122        TclThreadManager::getInstance().threadCounter_++;
    96123        std::string name = getConvertedValue<unsigned int, std::string>(TclThreadManager::getInstance().threadCounter_);
     
    132159                    if (bundle->finished_)
    133160                    {
    134                         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
    135 #if (BOOST_VERSION >= 103500)
     161                        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    136162                        boost::mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
    137 #else
    138                         boost::try_mutex::scoped_try_lock interpreter_lock(bundle->interpreterMutex_);
    139 #endif
    140163                        try
    141164                        {
    142165                            while (!interpreter_lock.try_lock())
    143166                            {
    144                                 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
    145 #if (BOOST_VERSION >= 103500)
     167                                orxonoxEvalCondition_g.notify_one();
    146168                                boost::this_thread::yield();
    147 #else
    148                                 boost::thread::yield();
    149 #endif
    150169                            }
    151170                        } catch (...) {}
     
    157176                }
    158177
    159                 TclThreadManager::getInstance().orxonoxEvalCondition_.notify_one();
    160 #if (BOOST_VERSION >= 103500)
     178                orxonoxEvalCondition_g.notify_one();
    161179                boost::this_thread::yield();
    162 #else
    163                 boost::thread::yield();
    164 #endif
    165180            }
    166181
     
    181196    std::string TclThreadManager::query(unsigned int threadID, const std::string& command)
    182197    {
    183         return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_.id_, threadID, command);
     198        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_->id_, threadID, command);
    184199    }
    185200
     
    191206        output += "\t\t";
    192207        {
    193             boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queueMutex_);
    194             output += getConvertedValue<unsigned int, std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queue_.size());
     208            boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queueMutex_);
     209            output += getConvertedValue<unsigned int, std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_->queue_.size());
    195210        }
    196211        output += "\t\t";
     
    198213        COUT(0) << output << std::endl;
    199214
    200         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     215        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    201216        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it)
    202217        {
     
    209224            output += "\t\t";
    210225            {
    211 #if (BOOST_VERSION >= 103500)
    212226                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
    216227                if (interpreter_lock.try_lock())
    217228                    output += "ready";
     
    228239        if (threadID == 0)
    229240        {
    230             bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     241            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
    231242            COUT(0) << "Queue dump of Orxonox:" << std::endl;
    232243        }
     
    254265        TclInterpreterBundle* bundle = 0;
    255266        if (threadID == 0)
    256             bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     267            bundle = TclThreadManager::getInstance().orxonoxInterpreterBundle_;
    257268        else
    258269            if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID)))
     
    334345    TclInterpreterBundle* TclThreadManager::getInterpreterBundle(unsigned int threadID)
    335346    {
    336         boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     347        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    337348        std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.find(threadID);
    338349        if (it != this->interpreterBundles_.end())
     
    347358    }
    348359
     360    Tcl::interpreter* TclThreadManager::getTclInterpreter(unsigned int threadID)
     361    {
     362        return this->getInterpreterBundle(threadID)->interpreter_;
     363    }
     364
    349365    std::string TclThreadManager::dumpList(const std::list<unsigned int>& list)
    350366    {
     
    362378    void TclThreadManager::error(const std::string& error)
    363379    {
    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)
     380        if (boost::this_thread::get_id() != threadID_g)
     381        {
     382            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     383            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
     384            {
    374385                boost::this_thread::yield();
    375 #else
    376                 boost::thread::yield();
    377 #endif
    378386                return;
    379387            }
     
    385393    void TclThreadManager::debug(const std::string& error)
    386394    {
    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)
     395        if (boost::this_thread::get_id() != threadID_g)
     396        {
     397            boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     398            if (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
     399            {
    397400                boost::this_thread::yield();
    398 #else
    399                 boost::thread::yield();
    400 #endif
    401401                return;
    402402            }
     
    408408    void TclThreadManager::pushCommandToQueue(const std::string& command)
    409409    {
    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);
     410        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     411        while (this->orxonoxInterpreterBundle_->queue_.size() >= TCLTHREADMANAGER_MAX_QUEUE_LENGTH)
     412            fullQueueCondition_g.wait(queue_lock);
     413
     414        this->orxonoxInterpreterBundle_->queue_.push_back(command);
    415415    }
    416416
    417417    void TclThreadManager::forceCommandToFrontOfQueue(const std::string& command)
    418418    {
    419         boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    420         this->orxonoxInterpreterBundle_.queue_.push_front(command);
     419        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     420        this->orxonoxInterpreterBundle_->queue_.push_front(command);
    421421    }
    422422
    423423    std::string TclThreadManager::popCommandFromQueue()
    424424    {
    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();
     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        fullQueueCondition_g.notify_one();
    429429        return temp;
    430430    }
     
    432432    bool TclThreadManager::queueIsEmpty()
    433433    {
    434         boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_.queueMutex_);
    435         return this->orxonoxInterpreterBundle_.queue_.empty();
     434        boost::mutex::scoped_lock queue_lock(this->orxonoxInterpreterBundle_->queueMutex_);
     435        return this->orxonoxInterpreterBundle_->queue_.empty();
    436436    }
    437437
     
    505505        if (querier)
    506506        {
    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);
     507            if (this->updateQueriersList(querier, this->orxonoxInterpreterBundle_))
     508            {
     509                boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
     510                orxonoxEvalCondition_g.wait(interpreter_lock);
    515511
    516512                if (!CommandExecutor::execute(command, false))
     
    521517            }
    522518
    523             boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_.queriersMutex_);
    524             this->orxonoxInterpreterBundle_.queriers_.clear();
     519            boost::mutex::scoped_lock queriers_lock(this->orxonoxInterpreterBundle_->queriersMutex_);
     520            this->orxonoxInterpreterBundle_->queriers_.clear();
    525521        }
    526522        return output;
     
    533529            target = this->getInterpreterBundle(threadID);
    534530        else
    535             target = &this->orxonoxInterpreterBundle_;
     531            target = this->orxonoxInterpreterBundle_;
    536532
    537533        std::string output = "";
     
    542538                querier = this->getInterpreterBundle(querierID);
    543539            else
    544                 querier = &this->orxonoxInterpreterBundle_;
     540                querier = this->orxonoxInterpreterBundle_;
    545541
    546542            if (querier)
     
    548544                if (this->updateQueriersList(querier, target))
    549545                {
    550 #if (BOOST_VERSION >= 103500)
    551546                    boost::mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
    552 #else
    553                     boost::try_mutex::scoped_try_lock interpreter_lock(target->interpreterMutex_);
    554 #endif
    555547                    bool successfullyLocked = false;
    556548                    try
     
    562554                            while (!interpreter_lock.try_lock())
    563555                            {
    564 #if (BOOST_VERSION >= 103500)
    565556                                boost::this_thread::yield();
    566 #else
    567                                 boost::thread::yield();
    568 #endif
    569557                            }
    570558
     
    599587    {
    600588        {
    601             this->orxonoxEvalCondition_.notify_one();
    602 #if (BOOST_VERSION >= 103500)
     589            orxonoxEvalCondition_g.notify_one();
    603590            boost::this_thread::yield();
    604 #else
    605             boost::thread::yield();
    606 #endif
    607         }
    608 
    609         {
    610             boost::mutex::scoped_lock bundles_lock(this->bundlesMutex_);
     591        }
     592
     593        {
     594            boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    611595            for (std::map<unsigned int, TclInterpreterBundle*>::iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
    612596            {
     
    626610
    627611        {
    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
     612            boost::mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_->interpreterMutex_);
    633613            unsigned long maxtime = (unsigned long)(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE);
    634614            Ogre::Timer timer;
     
    644624    std::list<unsigned int> TclThreadManager::getThreadList() const
    645625    {
    646         boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     626        boost::mutex::scoped_lock bundles_lock(bundlesMutex_g);
    647627        std::list<unsigned int> threads;
    648628        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
     
    654634    {
    655635        TclThreadManager::getInstance().debug("TclThread_execute: " + command);
    656 #if (BOOST_VERSION >= 103500)
    657636        boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
    658 #else
    659         boost::try_mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
    660 #endif
    661637        try
    662638        {
  • code/branches/netp6/src/core/TclThreadManager.h

    r3196 r3264  
    3535#include <map>
    3636#include <string>
    37 #include <boost/thread/condition.hpp>
    38 #include <boost/thread/mutex.hpp>
    39 #include <boost/thread/thread.hpp>
    40 
    4137#include "core/OrxonoxClass.h"
    4238
    4339namespace orxonox
    4440{
    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     };
     41    // Internal struct
     42    struct TclInterpreterBundle;
    6643
    6744    class _CoreExport TclThreadManager : public OrxonoxClass
     
    10178
    10279            Tcl::interpreter* createNewTclInterpreter(const std::string& threadID);
     80            Tcl::interpreter* getTclInterpreter(unsigned int threadID);
    10381            TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
    10482            std::string dumpList(const std::list<unsigned int>& list);
     
    11997
    12098            unsigned int threadCounter_;
    121             TclInterpreterBundle orxonoxInterpreterBundle_;
     99            TclInterpreterBundle* orxonoxInterpreterBundle_;
    122100            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
    131101
    132102            static TclThreadManager* singletonRef_s;
Note: See TracChangeset for help on using the changeset viewer.