summaryrefslogtreecommitdiff
path: root/includes/Handle.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-12-05 00:44:55 -0800
committerPixel <pixel@nobis-crew.org>2011-12-05 00:44:55 -0800
commitb419f3e159212c9998b3f86c1fee332620472f4e (patch)
tree8fe0edcda87f7ee43c2fb8a03f6f576f31ac3057 /includes/Handle.h
parent67432fe6501e1ae011870310b1dbcfb49b5233a8 (diff)
Making the ref counter on Handles thread-safe. Not that it renders the usage of Handles thread-safe, but at least one can now transmit Handles over threads safely without risking a refcount bug.
Diffstat (limited to 'includes/Handle.h')
-rw-r--r--includes/Handle.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/includes/Handle.h b/includes/Handle.h
index e3ff356..1b04556 100644
--- a/includes/Handle.h
+++ b/includes/Handle.h
@@ -3,6 +3,7 @@
#include <Exceptions.h>
#include <Printer.h>
#include <BString.h>
+#include <Atomic.h>
namespace Balau {
@@ -57,9 +58,9 @@ class Handle {
protected:
Handle() : m_refCount(0) { }
private:
- void addRef() { m_refCount++; }
+ void addRef() { Atomic::Increment(&m_refCount); }
void delRef() {
- if (--m_refCount == 0) {
+ if (Atomic::Decrement(&m_refCount) == 0) {
if (!isClosed())
close();
delete this;
@@ -69,7 +70,7 @@ class Handle {
template<class T>
friend class IO;
- int m_refCount;
+ volatile int m_refCount;
};
class HPrinter : public Handle {