1 #include "qui/threading/ThreadManager.hpp"
2 #include "qui/threading/InterpreterThread.hpp"
5 #include <QThreadStorage>
7 ThreadManager& ThreadManagerFactory() {
8 static ThreadManager *mgr;
10 mgr = new ThreadManager;
15 ThreadManager::ThreadManager()
17 // initialize thread variable
21 InterpreterThread *ThreadManager::create_interpreter()
23 static QMutex interpreter_lock;
24 static InterpreterThread *interpreter_thread;
25 if (interpreter_lock.tryLock()) {
26 // we're the first thread
27 interpreter_thread = new InterpreterThread();
29 // someone already started a copy of the interpreter
30 return interpreter_thread;
33 GuiProxy *ThreadManager::get_gui_proxy()
35 static GuiProxy *master;
36 static QThreadStorage <GuiProxy *> storage;
38 // we don't have a master object so we probably should make one
39 assert (storage.hasLocalData() == false);
40 master = new GuiProxy;
42 QMessageBox::critical(0, "Memory error", "Out of memory");
44 storage.setLocalData(master);
46 } else if (storage.hasLocalData()) {
47 // we've been initialized properly
48 return storage.localData();
50 // we have a master, but not a local proxy,
51 GuiProxy *client = new GuiProxy(master);
53 QMessageBox::critical(0, "Memory error", "Out of memory");
55 storage.setLocalData(client);