|
From: <ba...@us...> - 2007-04-15 20:59:49
|
Revision: 395
http://svn.sourceforge.net/cadcdev/?rev=395&view=rev
Author: bardtx
Date: 2007-04-15 13:59:34 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
tiki: make refcnt/refptr /actually/ thread-safe on win32 (we need some
solution for other plats that can have multiple cores still probably...)
Modified Paths:
--------------
tiki/include/Tiki/refcnt.h
tiki/src/base/object.cpp
Modified: tiki/include/Tiki/refcnt.h
===================================================================
--- tiki/include/Tiki/refcnt.h 2007-02-28 20:04:09 UTC (rev 394)
+++ tiki/include/Tiki/refcnt.h 2007-04-15 20:59:34 UTC (rev 395)
@@ -37,7 +37,11 @@
void unref();
protected:
+#if TIKI_PLAT == TIKI_WIN32
+ long m_refcnt;
+#else
int m_refcnt;
+#endif
};
/// A "smart pointer" to handle the RefCnt objects.
Modified: tiki/src/base/object.cpp
===================================================================
--- tiki/src/base/object.cpp 2007-02-28 20:04:09 UTC (rev 394)
+++ tiki/src/base/object.cpp 2007-04-15 20:59:34 UTC (rev 395)
@@ -25,19 +25,29 @@
void RefCnt::ref() {
assert( this != NULL );
+
+ // This actually ought to be in plat, probably...
+#if TIKI_PLAT == TIKI_WIN32
+ InterlockedIncrement(&m_refcnt);
+#else
m_refcnt++;
+#endif
}
void RefCnt::unref() {
assert( this != NULL );
+#if TIKI_PLAT == TIKI_WIN32
+ InterlockedDecrement(&m_refcnt);
+#else
m_refcnt--;
+#endif
+
if (m_refcnt < 0) {
Debug::printf("RefCnt::unref() refcount underflow! this=%p\n", this);
assert( false );
- } else {
- if (m_refcnt == 0)
- delete this;
+ } else if (m_refcnt == 0) {
+ delete this;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|