Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 19, 2009, 2:12:50 AM (15 years ago)
Author:
landauf
Message:

Completely rewrote TclThreadManager. This fixes several bugs from the initial implementation. The main features work fine now, but some tasks are still open (for example destroying a thread or implementing a queue size limit).

I hope this doesn't cause any troubles because I used the TclThreadManager-version from netp6 as a draft for the reimplementation. I've also applied the c-style-cast-fixes from core.

I tested this with boost 1.37, I hope it also works with 1.35 (I haven't seen any remarkable changes in the log). However it won't work with boost 1.34.1 and lower, but this change already happened back in netp6, so please update your dependencies if you're still using an old version (the current release is 1.39 btw).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/TclThreadManager.h

    r3304 r3307  
    3333
    3434#include <cassert>
    35 #include <list>
    3635#include <map>
    3736#include <string>
    38 #include "core/OrxonoxClass.h"
     37
     38#include "OrxonoxClass.h"
     39
     40namespace boost
     41{
     42    // forward declarations
     43    class mutex;
     44    class shared_mutex;
     45    class condition_variable;
     46}
    3947
    4048namespace orxonox
    4149{
    42     // Internal struct
    43     struct TclInterpreterBundle;
    44 
    4550    class _CoreExport TclThreadManager : public OrxonoxClass
    4651    {
    47         friend class IRC;
    4852        friend class TclBind;
     53        friend void tclThread(TclInterpreterBundle* bundle, std::string command);
    4954
    5055        public:
    5156            TclThreadManager(Tcl::interpreter* interpreter);
    52             ~TclThreadManager();
     57            virtual ~TclThreadManager();
    5358
    54             static TclThreadManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
     59            static TclThreadManager& getInstance() { assert(TclThreadManager::singletonPtr_s); return *TclThreadManager::singletonPtr_s; }
    5560
    56             static unsigned int create();
    57             static unsigned int createID(unsigned int threadID);
    58             static void destroy(unsigned int threadID);
    59             static void execute(unsigned int threadID, const std::string& command);
    60             static std::string query(unsigned int threadID, const std::string& command);
    61             static void status();
    62             static void dump(unsigned int threadID);
    63             static void flush(unsigned int threadID);
     61            static unsigned int      create();
     62            static Tcl::interpreter* createWithId(unsigned int id);
     63            static void              destroy(unsigned int id);
     64            static void              execute(unsigned int target_id, const std::string& command);
     65            static std::string       query(unsigned int target_id, const std::string& command);
    6466
    6567            void error(const std::string& error);
     
    7173
    7274        private:
    73             TclThreadManager(const TclThreadManager& other);
     75            static void tcl_execute(const Tcl::object& args);
     76            static void tcl_crossexecute(int target_id, const Tcl::object& args);
     77            static std::string tcl_query(int source_id, const Tcl::object& args);
     78            static std::string tcl_crossquery(int source_id, int target_id, const Tcl::object& args);
     79            static bool tcl_running(int id);
    7480
    75             static void tcl_execute(Tcl::object const &args);
    76             static std::string tcl_query(int querierID, Tcl::object const &args);
    77             static std::string tcl_crossquery(int querierID, int threadID, Tcl::object const &args);
    78             static bool tcl_running(int threadID);
     81            void _execute(unsigned int target_id, const std::string& command);
     82            std::string _query(unsigned int source_id, unsigned int target_id, const std::string& command, bool bUseCommandExecutor = false);
    7983
    80             Tcl::interpreter* createNewTclInterpreter(const std::string& threadID);
    81             Tcl::interpreter* getTclInterpreter(unsigned int threadID);
    82             TclInterpreterBundle* getInterpreterBundle(unsigned int threadID);
     84            TclInterpreterBundle* getInterpreterBundle(unsigned int id);
    8385            std::string dumpList(const std::list<unsigned int>& list);
    8486
    85             void pushCommandToQueue(const std::string& command);
    86             void forceCommandToFrontOfQueue(const std::string& command);
    87             std::string popCommandFromQueue();
    88             bool queueIsEmpty();
     87            std::string eval(TclInterpreterBundle* bundle, const std::string& command);
    8988
    90             void pushCommandToQueue(unsigned int threadID, const std::string& command);
    91             std::string popCommandFromQueue(unsigned int threadID);
    92             bool queueIsEmpty(unsigned int threadID);
     89            static TclThreadManager* singletonPtr_s;                            ///< Singleton pointer
    9390
    94             bool updateQueriersList(TclInterpreterBundle* querier, TclInterpreterBundle* target);
    95 
    96             std::string evalQuery(unsigned int querierID, const std::string& command);
    97             std::string evalQuery(unsigned int querierID, unsigned int threadID, const std::string& command);
    98 
    99             unsigned int threadCounter_;
    100             TclInterpreterBundle* orxonoxInterpreterBundle_;
    101             std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_;
    102 
    103             static TclThreadManager* singletonRef_s;
     91            unsigned int numInterpreterBundles_;                                ///< Number of created Tcl-interpreters (only used for auto-numbered interpreters, not affected by @ref createWithId)
     92            std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_;  ///< A map containing all Tcl-interpreters
     93            boost::shared_mutex* interpreterBundlesMutex_;                      ///< A mutex used to synchronize threads when accessing @ref interpreterBundles_
     94            TclThreadList<std::string>* messageQueue_;                          ///< A queue to pass messages from Tcl-threads to the main thread
     95            boost::mutex* mainInterpreterMutex_;                                ///< A mutex to synchronize queries to the main interpreter
    10496    };
    10597
    106     _CoreExport void tclThread(TclInterpreterBundle* interpreterBundle, std::string command);
     98    _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command);
    10799}
    108100
Note: See TracChangeset for help on using the changeset viewer.