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 const 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();
28 interpreter_thread->start();
30 return interpreter_thread;
31 // someone already started a copy of the interpreter
34 GuiProxy *ThreadManager::get_gui_proxy()
36 static GuiProxy *master;
37 static QThreadStorage <GuiProxy *> storage;
39 // we don't have a master object so we probably should make one
40 assert (storage.hasLocalData() == false);
41 master = new GuiProxy;
43 QMessageBox::critical(0, "Memory error", "Out of memory");
45 storage.setLocalData(master);
47 } else if (storage.hasLocalData()) {
48 // we've been initialized properly
49 return storage.localData();
51 // we have a master, but not a local proxy,
52 GuiProxy *client = new GuiProxy(master);
54 QMessageBox::critical(0, "Memory error", "Out of memory");
56 storage.setLocalData(client);