Changeset 3313 for code/trunk/src/core/TclThreadManager.h
- Timestamp:
- Jul 19, 2009, 2:58:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/TclThreadManager.h
r3308 r3313 33 33 34 34 #include <cassert> 35 #include <list> 35 36 #include <map> 36 37 #include <string> 37 38 #include "OrxonoxClass.h" 38 #include "core/OrxonoxClass.h" 39 39 40 40 namespace orxonox 41 41 { 42 // Internal struct 43 struct TclInterpreterBundle; 44 42 45 class _CoreExport TclThreadManager : public OrxonoxClass 43 46 { 47 friend class IRC; 44 48 friend class TclBind; 45 friend void tclThread(TclInterpreterBundle* bundle, std::string command);46 49 47 50 public: 48 51 TclThreadManager(Tcl::interpreter* interpreter); 49 virtual~TclThreadManager();52 ~TclThreadManager(); 50 53 51 static TclThreadManager& getInstance() { assert( TclThreadManager::singletonPtr_s); return *TclThreadManager::singletonPtr_s; }54 static TclThreadManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 52 55 53 static unsigned int create(); 54 static Tcl::interpreter* createWithId(unsigned int id); 55 static void destroy(unsigned int id); 56 static void execute(unsigned int target_id, const std::string& command); 57 static std::string query(unsigned int target_id, const std::string& command); 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); 58 64 59 65 void error(const std::string& error); … … 65 71 66 72 private: 67 static void tcl_execute(const Tcl::object& args); 68 static void tcl_crossexecute(int target_id, const Tcl::object& args); 69 static std::string tcl_query(int source_id, const Tcl::object& args); 70 static std::string tcl_crossquery(int source_id, int target_id, const Tcl::object& args); 71 static bool tcl_running(int id); 73 TclThreadManager(const TclThreadManager& other); 72 74 73 void _execute(unsigned int target_id, const std::string& command); 74 std::string _query(unsigned int source_id, unsigned int target_id, const std::string& command, bool bUseCommandExecutor = false); 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); 75 79 76 TclInterpreterBundle* getInterpreterBundle(unsigned int id); 80 Tcl::interpreter* createNewTclInterpreter(const std::string& threadID); 81 Tcl::interpreter* getTclInterpreter(unsigned int threadID); 82 TclInterpreterBundle* getInterpreterBundle(unsigned int threadID); 77 83 std::string dumpList(const std::list<unsigned int>& list); 78 84 79 std::string eval(TclInterpreterBundle* bundle, const std::string& command); 85 void pushCommandToQueue(const std::string& command); 86 void forceCommandToFrontOfQueue(const std::string& command); 87 std::string popCommandFromQueue(); 88 bool queueIsEmpty(); 80 89 81 static TclThreadManager* singletonPtr_s; ///< Singleton pointer 90 void pushCommandToQueue(unsigned int threadID, const std::string& command); 91 std::string popCommandFromQueue(unsigned int threadID); 92 bool queueIsEmpty(unsigned int threadID); 82 93 83 unsigned int numInterpreterBundles_; ///< Number of created Tcl-interpreters (only used for auto-numbered interpreters, not affected by @ref createWithId) 84 std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_; ///< A map containing all Tcl-interpreters 85 boost::shared_mutex* interpreterBundlesMutex_; ///< A mutex used to synchronize threads when accessing @ref interpreterBundles_ 86 TclThreadList<std::string>* messageQueue_; ///< A queue to pass messages from Tcl-threads to the main thread 87 boost::mutex* mainInterpreterMutex_; ///< A mutex to synchronize queries to the main interpreter 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; 88 104 }; 89 105 90 _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command);106 _CoreExport void tclThread(TclInterpreterBundle* interpreterBundle, std::string command); 91 107 } 92 108
Note: See TracChangeset
for help on using the changeset viewer.