summaryrefslogtreecommitdiff
path: root/tests/glibmm_mainloop/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/glibmm_mainloop/main.cc')
-rw-r--r--tests/glibmm_mainloop/main.cc44
1 files changed, 24 insertions, 20 deletions
diff --git a/tests/glibmm_mainloop/main.cc b/tests/glibmm_mainloop/main.cc
index de1a7514..9a9cf291 100644
--- a/tests/glibmm_mainloop/main.cc
+++ b/tests/glibmm_mainloop/main.cc
@@ -16,10 +16,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <cstdlib> // EXIT_SUCCESS, EXIT_FAILURE
#include <glibmm.h>
-#include <thread>
#include <iostream>
-#include <cstdlib> // EXIT_SUCCESS, EXIT_FAILURE
+#include <thread>
namespace
{
@@ -32,37 +32,40 @@ enum InvokeStatus
InvokeStatus invoked_in_thread[2] = { NOT_INVOKED, NOT_INVOKED };
-void quit_loop(const Glib::RefPtr<Glib::MainLoop>& mainloop)
+void
+quit_loop(const Glib::RefPtr<Glib::MainLoop>& mainloop)
{
mainloop->quit();
}
-bool mark_and_quit(const std::thread::id& expected_thread_id,
- int thread_nr, const Glib::RefPtr<Glib::MainLoop>& mainloop)
+bool
+mark_and_quit(const std::thread::id& expected_thread_id, int thread_nr,
+ const Glib::RefPtr<Glib::MainLoop>& mainloop)
{
- invoked_in_thread[thread_nr] =
- (std::this_thread::get_id() == expected_thread_id) ?
- INVOKED_IN_RIGHT_THREAD : INVOKED_IN_WRONG_THREAD;
+ invoked_in_thread[thread_nr] = (std::this_thread::get_id() == expected_thread_id)
+ ? INVOKED_IN_RIGHT_THREAD
+ : INVOKED_IN_WRONG_THREAD;
mainloop->get_context()->signal_idle().connect_once(
sigc::bind(sigc::ptr_fun(quit_loop), mainloop));
return false;
}
-void thread_function(const std::thread::id& first_thread_id,
- const Glib::RefPtr<Glib::MainLoop>& first_mainloop)
+void
+thread_function(
+ const std::thread::id& first_thread_id, const Glib::RefPtr<Glib::MainLoop>& first_mainloop)
{
auto second_context = Glib::MainContext::create();
auto second_mainloop = Glib::MainLoop::create(second_context);
// Show how Glib::MainContext::invoke() can be used for calling a function,
// possibly executed in another thread.
- Glib::MainContext::get_default()->invoke(sigc::bind(sigc::ptr_fun(mark_and_quit),
- first_thread_id, 0, first_mainloop));
+ Glib::MainContext::get_default()->invoke(
+ sigc::bind(sigc::ptr_fun(mark_and_quit), first_thread_id, 0, first_mainloop));
// If this thread owns second_context, invoke() will call mark_and_quit() directly.
bool is_owner = second_context->acquire();
- second_context->invoke(sigc::bind(sigc::ptr_fun(mark_and_quit),
- std::this_thread::get_id(), 1, second_mainloop));
+ second_context->invoke(
+ sigc::bind(sigc::ptr_fun(mark_and_quit), std::this_thread::get_id(), 1, second_mainloop));
if (is_owner)
second_context->release();
@@ -72,7 +75,8 @@ void thread_function(const std::thread::id& first_thread_id,
} // anonymous namespace
-int main(int, char**)
+int
+main(int, char**)
{
Glib::init();
@@ -109,16 +113,16 @@ int main(int, char**)
case INVOKED_IN_RIGHT_THREAD:
break;
case NOT_INVOKED:
- std::cout << "Function that should be invoked in " << N[i]
- << " thread was not called." << std::endl;
+ std::cout << "Function that should be invoked in " << N[i] << " thread was not called."
+ << std::endl;
break;
case INVOKED_IN_WRONG_THREAD:
std::cout << "Function that should be invoked in " << N[i]
- << " thread was called in another thread." << std::endl;
+ << " thread was called in another thread." << std::endl;
break;
default:
- std::cout << "Unknown value: invoked_in_thread[" << i << "]="
- << invoked_in_thread[i] << std::endl;
+ std::cout << "Unknown value: invoked_in_thread[" << i << "]=" << invoked_in_thread[i]
+ << std::endl;
break;
}
}