Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/TclThreadManager.h @ 3307

Last change on this file since 3307 was 3307, checked in by landauf, 15 years ago

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).

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _TclThreadManager_H__
30#define _TclThreadManager_H__
31
32#include "CorePrereqs.h"
33
34#include <cassert>
35#include <map>
36#include <string>
37
38#include "OrxonoxClass.h"
39
40namespace boost
41{
42    // forward declarations
43    class mutex;
44    class shared_mutex;
45    class condition_variable;
46}
47
48namespace orxonox
49{
50    class _CoreExport TclThreadManager : public OrxonoxClass
51    {
52        friend class TclBind;
53        friend void tclThread(TclInterpreterBundle* bundle, std::string command);
54
55        public:
56            TclThreadManager(Tcl::interpreter* interpreter);
57            virtual ~TclThreadManager();
58
59            static TclThreadManager& getInstance() { assert(TclThreadManager::singletonPtr_s); return *TclThreadManager::singletonPtr_s; }
60
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);
66
67            void error(const std::string& error);
68            void debug(const std::string& error);
69
70            void update(const Clock& time);
71
72            std::list<unsigned int> getThreadList() const;
73
74        private:
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);
80
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);
83
84            TclInterpreterBundle* getInterpreterBundle(unsigned int id);
85            std::string dumpList(const std::list<unsigned int>& list);
86
87            std::string eval(TclInterpreterBundle* bundle, const std::string& command);
88
89            static TclThreadManager* singletonPtr_s;                            ///< Singleton pointer
90
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
96    };
97
98    _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command);
99}
100
101#endif /* _TclThreadManager_H__ */
Note: See TracBrowser for help on using the repository browser.