diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2014-07-07 20:52:15 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2014-07-07 20:52:15 -0500 |
commit | 6979bfa2ec2732c2c9f457b25aaf26a65f5d773e (patch) | |
tree | e2ccd5902fa6b2a203153ad25ca9df8965b2ee14 | |
parent | 19e94ca5179704ee5d0e7514ac9fdece6d678d34 (diff) | |
download | ayatana-indicator-datetime-6979bfa2ec2732c2c9f457b25aaf26a65f5d773e.tar.gz ayatana-indicator-datetime-6979bfa2ec2732c2c9f457b25aaf26a65f5d773e.tar.bz2 ayatana-indicator-datetime-6979bfa2ec2732c2c9f457b25aaf26a65f5d773e.zip |
in snap.cpp, use std::call_once() as suggested by tedg
-rw-r--r-- | src/snap.cpp | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/snap.cpp b/src/snap.cpp index 8a86521..4495287 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -29,6 +29,7 @@ #include <glib/gi18n.h> #include <glib.h> +#include <mutex> // std::call_once() #include <set> #include <string> @@ -64,11 +65,8 @@ public: m_loop_end_time(clock->localtime().add_full(0, 0, 0, 0, (int)duration_minutes, 0.0)) { // init GST once - static bool gst_initialized = false; - if (!gst_initialized) - { - gst_initialized = true; - + static std::once_flag once; + std::call_once(once, [](){ GError* error = nullptr; gst_init_check (nullptr, nullptr, &error); if (error) @@ -76,7 +74,7 @@ public: g_critical("Unable to play alarm sound: %s", error->message); g_error_free(error); } - } + }); if (m_loop) { @@ -218,14 +216,11 @@ public: { // ensure notify_init() is called once // before we start popping up dialogs - static bool m_nn_inited = false; - if (G_UNLIKELY(!m_nn_inited)) - { + static std::once_flag once; + std::call_once(once, [](){ if(!notify_init("indicator-datetime-service")) g_critical("libnotify initialization failed"); - - m_nn_inited = true; - } + }); show(); } @@ -356,13 +351,11 @@ private: static bool get_interactive() { static bool interactive; - static bool inited = false; - if (G_UNLIKELY(!inited)) - { + static std::once_flag once; + std::call_once(once, [](){ interactive = get_server_caps().count("actions") != 0; - inited = true; - } + }); return interactive; } |