diff options
author | Kjell Ahlstedt <kjell.ahlstedt@bredband.net> | 2012-03-22 18:51:46 +0100 |
---|---|---|
committer | Kjell Ahlstedt <kjell.ahlstedt@bredband.net> | 2012-03-22 18:51:46 +0100 |
commit | 5776341bd182931ae415d5eeaedbf71bca91e525 (patch) | |
tree | 19deff899b540dc31afeec39d78f9a0f1409a1e9 /examples | |
parent | f4b8b84e1acfab3b275578c47f3f21da716737d6 (diff) | |
download | glibmm-5776341bd182931ae415d5eeaedbf71bca91e525.tar.gz |
Dispatcher examples: Use Glib::signal_idle().connect_once().
* examples/thread/dispatcher.cc: Use Glib::signal_idle().connect_once().
* examples/thread/dispatcher2.cc: Use Glib::signal_idle().connect_once().
Rename class Dispatcher to ThreadDispatcher. Bug #396963
Diffstat (limited to 'examples')
-rw-r--r-- | examples/thread/dispatcher.cc | 8 | ||||
-rw-r--r-- | examples/thread/dispatcher2.cc | 26 |
2 files changed, 14 insertions, 20 deletions
diff --git a/examples/thread/dispatcher.cc b/examples/thread/dispatcher.cc index 1ed0c9c2..21833e7f 100644 --- a/examples/thread/dispatcher.cc +++ b/examples/thread/dispatcher.cc @@ -44,7 +44,7 @@ private: // Note that the thread does not write to the member data at all. It only // reads signal_increment_, which is only written to before the thread is - // lauched. Therefore, no locking is required. + // launched. Therefore, no locking is required. Glib::Threads::Thread* thread_; int id_; unsigned int progress_; @@ -148,9 +148,6 @@ Application::Application() main_loop_ (Glib::MainLoop::create()), progress_threads_ (5) { - // Note that unless you're targetting an embedded platform, you can assume - // exceptions to be enabled. The #ifdef is only here to make the example - // compile in either case; you may ignore it otherwise. try { for (std::vector<ThreadProgress*>::size_type i = 0; i < progress_threads_.size(); ++i) @@ -181,8 +178,7 @@ Application::~Application() void Application::run() { // Install a one-shot idle handler to launch the threads. - Glib::signal_idle().connect( - sigc::bind_return(sigc::mem_fun(*this, &Application::launch_threads), false)); + Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Application::launch_threads)); main_loop_->run(); } diff --git a/examples/thread/dispatcher2.cc b/examples/thread/dispatcher2.cc index d42e2246..dd7d7de8 100644 --- a/examples/thread/dispatcher2.cc +++ b/examples/thread/dispatcher2.cc @@ -10,7 +10,7 @@ * of the program. * * Modified by J. Abelardo Gutierrez <jabelardo@cantv.net> - * to cast all gtkmm out and make it glimm only + * to cast all gtkmm out and make it glibmm only * * Note: This example is special stuff that's seldomly needed by the * vast majority of applications. Don't bother working out what this @@ -59,11 +59,10 @@ private: void thread_function(); }; -//TODO: Rename to avoid confusion with Glib::Dispatcher. murrayc -class Dispatcher : public sigc::trackable +class ThreadDispatcher : public sigc::trackable { public: - Dispatcher(); + ThreadDispatcher(); void launch_thread(); void end(); @@ -75,7 +74,7 @@ private: ThreadTimer::ThreadTimer() : time_ (0), - // Create a new dispatcher that is attached to the default main context, + // Create a new Glib::Dispatcher that is attached to the default main context, signal_increment_ (), // This pointer will be initialized later by the 2nd thread. signal_finished_ptr_ (NULL) @@ -90,7 +89,7 @@ ThreadTimer::~ThreadTimer() void ThreadTimer::launch() { // Unfortunately, the thread creation has to be fully synchronized in - // order to access the Dispatcher object instantiated by the 2nd thread. + // order to access the Glib::Dispatcher object instantiated by the 2nd thread. // So, let's do some kind of hand-shake using a mutex and a condition // variable. Glib::Threads::Mutex::Lock lock (startup_mutex_); @@ -165,7 +164,7 @@ void ThreadTimer::thread_function() // newly created MainContext context->signal_timeout().connect(sigc::mem_fun(*this, &ThreadTimer::timeout_handler), 1000); - // We need to lock while creating the Dispatcher instance, + // We need to lock while creating the Glib::Dispatcher instance, // in order to ensure memory visibility. Glib::Threads::Mutex::Lock lock (startup_mutex_); @@ -188,24 +187,24 @@ void ThreadTimer::thread_function() // initialize static member: ThreadTimer::type_signal_end ThreadTimer::signal_end_; -Dispatcher::Dispatcher() +ThreadDispatcher::ThreadDispatcher() : timer_ (NULL) { std::cout << "Thread Dispatcher Example #2" << std::endl; timer_ = new ThreadTimer(); - timer_->signal_end().connect(sigc::mem_fun(*this, &Dispatcher::end)); + timer_->signal_end().connect(sigc::mem_fun(*this, &ThreadDispatcher::end)); timer_->print(); } -void Dispatcher::launch_thread() +void ThreadDispatcher::launch_thread() { // launch the timer thread timer_->launch(); } -void Dispatcher::end() +void ThreadDispatcher::end() { // quit the main mainloop main_loop->quit(); @@ -219,11 +218,10 @@ int main(int, char**) Glib::init(); main_loop = Glib::MainLoop::create(); - Dispatcher dispatcher; + ThreadDispatcher dispatcher; // Install a one-shot idle handler to launch the threads - Glib::signal_idle().connect( - sigc::bind_return(sigc::mem_fun(dispatcher, &Dispatcher::launch_thread), false)); + Glib::signal_idle().connect_once(sigc::mem_fun(dispatcher, &ThreadDispatcher::launch_thread)); main_loop->run(); |