summaryrefslogtreecommitdiff
path: root/src/Idle.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-16 23:20:56 +0100
committerMax Kellermann <max@duempel.org>2013-01-16 23:23:47 +0100
commit36c814d26e2ef2b689e706b3e8db4777df4e2442 (patch)
treeed8da7ce0629e246494c247511ce43ab55dcfb76 /src/Idle.cxx
parentd769b74d6191c90fce08c97b5115e06209376eff (diff)
Idle: use std::atomic instead of GMutex
Diffstat (limited to 'src/Idle.cxx')
-rw-r--r--src/Idle.cxx34
1 files changed, 5 insertions, 29 deletions
diff --git a/src/Idle.cxx b/src/Idle.cxx
index fce0cb7da..f1423ebeb 100644
--- a/src/Idle.cxx
+++ b/src/Idle.cxx
@@ -26,11 +26,11 @@
#include "Idle.hxx"
#include "GlobalEvents.hxx"
+#include <atomic>
+
#include <assert.h>
-#include <glib.h>
-static unsigned idle_flags;
-static GMutex *idle_mutex = NULL;
+static std::atomic_uint idle_flags;
static const char *const idle_names[] = {
"database",
@@ -44,32 +44,15 @@ static const char *const idle_names[] = {
"update",
"subscription",
"message",
- NULL
+ nullptr
};
void
-idle_init(void)
-{
- g_assert(idle_mutex == NULL);
- idle_mutex = g_mutex_new();
-}
-
-void
-idle_deinit(void)
-{
- g_assert(idle_mutex != NULL);
- g_mutex_free(idle_mutex);
- idle_mutex = NULL;
-}
-
-void
idle_add(unsigned flags)
{
assert(flags != 0);
- g_mutex_lock(idle_mutex);
idle_flags |= flags;
- g_mutex_unlock(idle_mutex);
GlobalEvents::Emit(GlobalEvents::IDLE);
}
@@ -77,14 +60,7 @@ idle_add(unsigned flags)
unsigned
idle_get(void)
{
- unsigned flags;
-
- g_mutex_lock(idle_mutex);
- flags = idle_flags;
- idle_flags = 0;
- g_mutex_unlock(idle_mutex);
-
- return flags;
+ return idle_flags.fetch_and(0);
}
const char*const*