aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/RefCount.hxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/RefCount.hxx (renamed from src/refcount.h)44
1 files changed, 18 insertions, 26 deletions
diff --git a/src/refcount.h b/src/util/RefCount.hxx
index a882d76b0..9a45a585b 100644
--- a/src/refcount.h
+++ b/src/util/RefCount.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* Redistribution and use in source and binary forms, with or without
@@ -33,35 +33,27 @@
* A very simple reference counting library.
*/
-#ifndef MPD_REFCOUNT_H
-#define MPD_REFCOUNT_H
+#ifndef MPD_REFCOUNT_HXX
+#define MPD_REFCOUNT_HXX
-#include <glib.h>
-#include <stdbool.h>
+#include <atomic>
-struct refcount {
- gint n;
-};
+class RefCount {
+ std::atomic_uint n;
-static inline void
-refcount_init(struct refcount *r)
-{
- r->n = 1;
-}
+public:
+ constexpr RefCount():n(1) {}
-static inline void
-refcount_inc(struct refcount *r)
-{
- g_atomic_int_inc(&r->n);
-}
+ void Increment() {
+ ++n;
+ }
-/**
- * @return true if the number of references has been dropped to 0
- */
-static inline bool
-refcount_dec(struct refcount *r)
-{
- return g_atomic_int_dec_and_test(&r->n);
-}
+ /**
+ * @return true if the number of references has been dropped to 0
+ */
+ bool Decrement() {
+ return --n == 0;
+ }
+};
#endif