diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-26 21:31:26 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-26 21:31:26 +0000 |
commit | c39d4c6d143697ee8982df0833499a8de934dd9a (patch) | |
tree | cbc758f3921459c0f11a96f24f5ef251db0bf367 /cpp/sca/runtime/core/src/tuscany/gc.hpp | |
parent | 8eb242943144ad5ea57c7471e4a3e199bf5687d5 (diff) |
Refactored the value class. Cleaned up usage of namespaces to remove side effects from includes. Added a few util functions to help work with threads. Added synchronizations to make pointers thread safe. Adjusted store sample to refactoring.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@819220 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/sca/runtime/core/src/tuscany/gc.hpp')
-rw-r--r-- | cpp/sca/runtime/core/src/tuscany/gc.hpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/cpp/sca/runtime/core/src/tuscany/gc.hpp b/cpp/sca/runtime/core/src/tuscany/gc.hpp index 803ec31643..b0ed42a474 100644 --- a/cpp/sca/runtime/core/src/tuscany/gc.hpp +++ b/cpp/sca/runtime/core/src/tuscany/gc.hpp @@ -26,9 +26,7 @@ * Garbage collected pointer. */ -#include <ostream> - -using std::ostream; +#include <iostream> namespace tuscany { @@ -81,7 +79,7 @@ public: return countingRef->ptr; } - template<typename X> friend ostream& operator<<(ostream&, const gc_ptr<X>&); + template<typename X> friend std::ostream& operator<<(std::ostream&, const gc_ptr<X>&); private: struct CountingRef { @@ -95,12 +93,13 @@ private: void acquire(CountingRef* ref) throw() { if(ref) - ++ref->count; + __sync_add_and_fetch(&ref->count, 1); } void release() throw() { if(countingRef) { - if(--countingRef->count == 0) { + unsigned rc = __sync_sub_and_fetch(&countingRef->count, 1); + if(rc == 0) { delete countingRef->ptr; delete countingRef; } @@ -108,7 +107,7 @@ private: } }; -template<typename T> ostream& operator<<(ostream& out, const gc_ptr<T>& p) { +template<typename T> std::ostream& operator<<(std::ostream& out, const gc_ptr<T>& p) { return out << p.countingRef->ptr; } @@ -163,7 +162,7 @@ public: return countingRef->ptr; } - template<typename X> friend ostream& operator<<(ostream&, const gc_aptr<X>&); + template<typename X> friend std::ostream& operator<<(std::ostream&, const gc_aptr<X>&); private: struct CountingRef { @@ -177,12 +176,13 @@ private: void acquire(CountingRef* ref) throw() { if(ref) - ++ref->count; + __sync_add_and_fetch(&ref->count, 1); } void release() throw() { if(countingRef) { - if(--countingRef->count == 0) { + unsigned rc = __sync_sub_and_fetch(&countingRef->count, 1); + if(rc == 0) { delete[] countingRef->ptr; delete countingRef; } @@ -190,7 +190,7 @@ private: } }; -template<typename T> ostream& operator<<(ostream& out, const gc_aptr<T>& p) { +template<typename T> std::ostream& operator<<(std::ostream& out, const gc_aptr<T>& p) { return out << p.countingRef->ptr; } @@ -242,7 +242,7 @@ public: return ptr; } - template<typename X> friend ostream& operator<<(ostream&, const gc_counting_ptr<X>&); + template<typename X> friend std::ostream& operator<<(std::ostream&, const gc_counting_ptr<X>&); private: T* ptr; @@ -261,7 +261,7 @@ private: } }; -template<typename T> ostream& operator<<(ostream& out, const gc_counting_ptr<T>& p) { +template<typename T> std::ostream& operator<<(std::ostream& out, const gc_counting_ptr<T>& p) { return out << p.ptr; } |