[glibmm] resolver example: Use std::mutex instead of G_LOCK_DEFINE_STATIC.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] resolver example: Use std::mutex instead of G_LOCK_DEFINE_STATIC.
- Date: Thu, 26 Nov 2015 10:07:07 +0000 (UTC)
commit e60f9a07618deff695e3487b5032bf5c480495b5
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Nov 26 10:14:53 2015 +0100
resolver example: Use std::mutex instead of G_LOCK_DEFINE_STATIC.
As noticed by Kjell Ahlstedt:
https://bugzilla.gnome.org/show_bug.cgi?id=757674#c10
examples/network/resolver.cc | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc
index 483f65e..e6837b2 100644
--- a/examples/network/resolver.cc
+++ b/examples/network/resolver.cc
@@ -25,6 +25,7 @@
#include <giomm.h>
#include <thread>
#include <iostream>
+#include <mutex>
#include <cerrno>
#include <csignal>
@@ -54,7 +55,7 @@ usage (void)
exit (1);
}
-G_LOCK_DEFINE_STATIC (response);
+static std::mutex response_mutex;
static bool
idle_quit ()
@@ -80,21 +81,20 @@ static void
print_resolved_name (const Glib::ustring& phys,
const Glib::ustring& name)
{
- G_LOCK (response);
+ std::lock_guard<std::mutex> lock_guard (response_mutex);
std::cout
<< Glib::ustring::compose ("Address: %1\n", phys)
<< Glib::ustring::compose ("Name: %1\n", name)
<< std::endl;
done_lookup ();
- G_UNLOCK (response);
}
static void
print_resolved_addresses (const Glib::ustring& name,
const std::list<Glib::RefPtr<Gio::InetAddress>>& addresses)
{
- G_LOCK (response);
+ std::lock_guard<std::mutex> lock_guard (response_mutex);
std::cout << Glib::ustring::compose ("Name: %1\n", name);
for (const auto& i : addresses)
{
@@ -103,14 +103,13 @@ print_resolved_addresses (const Glib::ustring& name,
std::cout << std::endl;
done_lookup ();
- G_UNLOCK (response);
}
static void
print_resolved_service (const Glib::ustring& service,
const std::list<Gio::SrvTarget>& targets)
{
- G_LOCK (response);
+ std::lock_guard<std::mutex> lock_guard (response_mutex);
std::cout << Glib::ustring::compose ("Service: %1\n", service);
for (const auto& i : targets)
{
@@ -124,7 +123,6 @@ print_resolved_service (const Glib::ustring& service,
std::cout << std::endl;
done_lookup ();
- G_UNLOCK (response);
}
static std::vector<Glib::ustring>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]