Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 12, 2008, 2:50:21 PM (17 years ago)
Author:
landauf
Message:
  • after a total rewrite of the TclThreadManager, there are some new problems, but most of the old ones are fixed. i commit this version to have a backup, not because it's finished.
  • 'exec' command is now called 'source' (tcl and orxonox)
  • 'orxonox' command is now called 'query' (tcl only)
  • added 'crossquery' command (tcl only)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/TclThreadManager.h

    r1247 r1255  
    3131
    3232#include <queue>
     33#include <map>
     34#include <list>
    3335
    3436#include <boost/thread/mutex.hpp>
     
    4345    class boost::thread;
    4446
    45     struct TclThread
     47    struct _CoreExport TclInterpreterBundle
    4648    {
    47         unsigned int threadID_;
     49        unsigned int id_;
     50
     51        std::list<std::string> queue_;
     52        boost::mutex queueMutex_;
     53
    4854        Tcl::interpreter* interpreter_;
    49         boost::thread* thread_;
    50         boost::mutex* evalMutex_;
    51         boost::mutex* stateMutex_;
    52         enum State
    53         {
    54             Ready,
    55             Busy,
    56             Finished,
    57             Error
    58         }* state_;
     55        std::string interpreterName_;
     56        boost::try_mutex interpreterMutex_;
     57
     58        std::list<unsigned int> queriers_;
     59        boost::mutex queriersMutex_;
     60
     61        bool running_;
     62        boost::mutex runningMutex_;
     63
     64        bool finished_;
     65        boost::mutex finishedMutex_;
     66        boost::condition finishedCondition_;
    5967    };
    6068
     
    6472            static TclThreadManager& getInstance();
    6573
    66             static void tclthread(unsigned int threadID, const std::string& command);
    6774            static unsigned int create();
    6875            static void destroy(unsigned int threadID);
    6976            static void execute(unsigned int threadID, const std::string& command);
    7077            static std::string query(unsigned int threadID, const std::string& command);
    71             static void status();
    72             static void dump(unsigned int threadID);
    7378
    74             static std::string tcl_query(int id, Tcl::object const &args);
    7579            static void tcl_execute(Tcl::object const &args);
     80            static std::string tcl_query(int querierID, Tcl::object const &args);
     81            static std::string tcl_crossquery(int querierID, int threadID, Tcl::object const &args);
     82            static bool tcl_running(int threadID);
    7683
    77             Tcl::interpreter* createTclInterpreter(unsigned int threadID) const;
    78             bool createTclThread();
    79             bool destroyTclThread(unsigned int threadID);
     84            Tcl::interpreter* createNewTclInterpreter(const std::string& threadID);
     85            TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
     86            std::string dumpList(const std::list<unsigned int>& list);
    8087
    81             void setState(TclThread* tclThread, TclThread::State state);
    82             TclThread::State getState(TclThread* tclThread);
     88            void pushCommandToQueue(const std::string& command);
     89            void forceCommandToFrontOfQueue(const std::string& command);
     90            std::string popCommandFromQueue();
     91            bool queueIsEmpty();
    8392
    84             void pushCommandBack(const std::string& command);
    85             std::string popCommandFront();
    86             bool isEmpty();
     93            void pushCommandToQueue(unsigned int threadID, const std::string& command);
     94            std::string popCommandFromQueue(unsigned int threadID);
     95            bool queueIsEmpty(unsigned int threadID);
    8796
    88             void pushCommandBack(unsigned int threadID, const std::string& command);
    89             std::string popCommandFront(unsigned int threadID);
    90             bool isEmpty(unsigned int threadID);
     97            bool updateQueriersList(TclInterpreterBundle* querier, TclInterpreterBundle* target);
    9198
    92             std::string eval(const std::string& command);
    93             std::string eval(unsigned int threadID, const std::string& command);
     99            std::string evalQuery(unsigned int querierID, const std::string& command);
     100            std::string evalQuery(unsigned int querierID, unsigned int threadID, const std::string& command);
    94101
    95102            virtual void tick(float dt);
     
    97104        private:
    98105            TclThreadManager();
     106            TclThreadManager(const TclThreadManager& other);
     107            ~TclThreadManager() {}
    99108
    100             bool isReady_;
    101             bool isQuerying_;
    102             unsigned int queryID_;
    103 
    104             unsigned int IDcount_;
    105             std::map<unsigned int, TclThread*> threads_;
    106             std::map<unsigned int, std::pair<std::queue<std::string>, boost::condition*> > threadQueues_;
    107             std::queue<std::string> orxonoxQueue_;
    108 
    109             boost::try_mutex orxonoxQueueMutex_;
    110             boost::try_mutex threadQueuesMutex_;
    111             boost::try_mutex threadsMutex_;
    112             boost::try_mutex orxonoxStateMutex_;
    113             boost::try_mutex orxonoxQueryMutex_;
    114 
    115             boost::condition orxonoxQueueCondition_;
     109            unsigned int threadCounter_;
     110            TclInterpreterBundle orxonoxInterpreterBundle_;
     111            std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_;
     112            boost::mutex bundlesMutex_;
     113            boost::condition fullQueueCondition_;
    116114            boost::condition orxonoxEvalCondition_;
    117115    };
    118116
    119     _CoreExport void tclThreadLoop(TclThread* tclThread);
     117    _CoreExport void tclThread(TclInterpreterBundle* interpreterBundle, std::string command);
    120118}
    121119
Note: See TracChangeset for help on using the changeset viewer.