Replace Glib::Threads with PBD::Thread (2/2)

This commit is contained in:
Robin Gareus 2022-02-28 22:34:02 +01:00
parent 24bbf403b9
commit 50abcc74b5
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
5 changed files with 13 additions and 14 deletions

View file

@ -37,7 +37,7 @@ TestUI::TestUI ()
pthread_set_name ("test_ui_thread"); pthread_set_name ("test_ui_thread");
run_loop_thread = Glib::Threads::Thread::self (); _run_loop_thread = PBD::Thread::self ();
set_event_loop_for_thread (this); set_event_loop_for_thread (this);

View file

@ -96,10 +96,9 @@ UI::UI (string application_name, string thread_name, int *argc, char ***argv)
} }
/* the GUI event loop runs in the main thread of the app, /* the GUI event loop runs in the main thread of the app,
which is assumed to have called this. * which is assumed to have called this.
*/ */
_run_loop_thread = PBD::Thread::self ();
run_loop_thread = Threads::Thread::self();
/* store "this" as the UI-for-thread of this thread, same argument /* store "this" as the UI-for-thread of this thread, same argument
as for previous line. as for previous line.
@ -144,9 +143,9 @@ UI::~UI ()
} }
bool bool
UI::caller_is_ui_thread () UI::caller_is_ui_thread () const
{ {
return Threads::Thread::self() == run_loop_thread; return caller_is_self ();
} }
int int

View file

@ -129,7 +129,7 @@ public:
/* Abstract UI interfaces */ /* Abstract UI interfaces */
bool caller_is_ui_thread (); bool caller_is_ui_thread () const;
/* Gtk-UI specific interfaces */ /* Gtk-UI specific interfaces */

View file

@ -58,7 +58,7 @@ BaseUI::RequestType BaseUI::Quit = BaseUI::new_request_type();
BaseUI::BaseUI (const string& loop_name) BaseUI::BaseUI (const string& loop_name)
: EventLoop (loop_name) : EventLoop (loop_name)
, m_context(MainContext::get_default()) , m_context(MainContext::get_default())
, run_loop_thread (0) , _run_loop_thread (0)
, request_channel (true) , request_channel (true)
{ {
base_ui_instance = this; base_ui_instance = this;
@ -69,6 +69,7 @@ BaseUI::BaseUI (const string& loop_name)
BaseUI::~BaseUI() BaseUI::~BaseUI()
{ {
delete _run_loop_thread;
} }
BaseUI::RequestType BaseUI::RequestType
@ -121,7 +122,7 @@ BaseUI::run ()
attach_request_source (); attach_request_source ();
Glib::Threads::Mutex::Lock lm (_run_lock); Glib::Threads::Mutex::Lock lm (_run_lock);
run_loop_thread = Glib::Threads::Thread::create (mem_fun (*this, &BaseUI::main_thread)); _run_loop_thread = PBD::Thread::create (boost::bind (&BaseUI::main_thread, this));
_running.wait (_run_lock); _running.wait (_run_lock);
} }
@ -130,7 +131,7 @@ BaseUI::quit ()
{ {
if (_main_loop && _main_loop->is_running()) { if (_main_loop && _main_loop->is_running()) {
_main_loop->quit (); _main_loop->quit ();
run_loop_thread->join (); _run_loop_thread->join ();
} }
} }

View file

@ -53,8 +53,7 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop
BaseUI* base_instance() { return base_ui_instance; } BaseUI* base_instance() { return base_ui_instance; }
Glib::RefPtr<Glib::MainLoop> main_loop() const { return _main_loop; } Glib::RefPtr<Glib::MainLoop> main_loop() const { return _main_loop; }
Glib::Threads::Thread* event_loop_thread() const { return run_loop_thread; } bool caller_is_self () const { assert (_run_loop_thread); return _run_loop_thread->caller_is_self (); }
bool caller_is_self () const { return Glib::Threads::Thread::self() == run_loop_thread; }
bool ok() const { return _ok; } bool ok() const { return _ok; }
@ -80,7 +79,7 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop
Glib::RefPtr<Glib::MainLoop> _main_loop; Glib::RefPtr<Glib::MainLoop> _main_loop;
Glib::RefPtr<Glib::MainContext> m_context; Glib::RefPtr<Glib::MainContext> m_context;
Glib::Threads::Thread* run_loop_thread; PBD::Thread* _run_loop_thread;
Glib::Threads::Mutex _run_lock; Glib::Threads::Mutex _run_lock;
Glib::Threads::Cond _running; Glib::Threads::Cond _running;