aboutsummaryrefslogtreecommitdiff
path: root/cpp/src/sfntly/port
diff options
context:
space:
mode:
authorarthurhsu <arthurhsu@google.com>2011-07-21 22:30:37 +0000
committerarthurhsu <arthurhsu@google.com>2011-07-21 22:30:37 +0000
commitfb8de4ba03f06a06bd8ae8f0f45d0244e496c269 (patch)
treecb3bfc0f744bc32ef8b5bd5891b7cfb4ddcd40b9 /cpp/src/sfntly/port
parent9ff77ab7a0ad76b0b4a13bf5e3ecee0f7f270e46 (diff)
downloadsfntly-fb8de4ba03f06a06bd8ae8f0f45d0244e496c269.tar.gz
Update for clang to successfully build sfntly.
Diffstat (limited to 'cpp/src/sfntly/port')
-rw-r--r--cpp/src/sfntly/port/atomic.h11
-rw-r--r--cpp/src/sfntly/port/refcount.h23
2 files changed, 29 insertions, 5 deletions
diff --git a/cpp/src/sfntly/port/atomic.h b/cpp/src/sfntly/port/atomic.h
index 10db2d5..4c2d65b 100644
--- a/cpp/src/sfntly/port/atomic.h
+++ b/cpp/src/sfntly/port/atomic.h
@@ -49,7 +49,12 @@ static inline size_t atomicDecrement(size_t* address) {
return OSAtomicDecrement32Barrier(reinterpret_cast<int32_t*>(address));
}
-#elif defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
+// Originally we check __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, however, there are
+// issues that clang not carring over this definition. Therefore we boldly
+// assume it's gcc or gcc-compatible here. Compilation shall still fail since
+// the intrinsics used are GCC-specific.
+
+#else
#include <stddef.h>
@@ -61,10 +66,6 @@ static inline size_t atomicDecrement(size_t* address) {
return __sync_sub_and_fetch(address, 1);
}
-#else
-
-#error "Compiler not supported"
-
#endif // WIN32
#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_ATOMIC_H_
diff --git a/cpp/src/sfntly/port/refcount.h b/cpp/src/sfntly/port/refcount.h
index c1e5a6d..ed1fa96 100644
--- a/cpp/src/sfntly/port/refcount.h
+++ b/cpp/src/sfntly/port/refcount.h
@@ -15,6 +15,29 @@
*/
// Object reference count and smart pointer implementation.
+
+// Smart pointer usage in sfntly:
+//
+// sfntly carries a smart pointer implementation like COM. Ref-countable object
+// type inherits from RefCounted<>, which have AddRef and Release just like
+// IUnknown (but no QueryInterface). Use a Ptr<> based smart pointer to hold
+// the object so that the object ref count is handled correctly.
+//
+// class Foo : public RefCounted<Foo> {
+// public:
+// static Foo* CreateInstance() {
+// Ptr<Foo> obj = new Foo(); // ref count = 1
+// return obj.detach();
+// }
+// };
+// typedef Ptr<Foo> FooPtr; // common short-hand notation
+// FooPtr obj;
+// obj.attach(Foo::CreatedInstance()); // ref count = 1
+// {
+// FooPtr obj2 = obj; // ref count = 2
+// } // ref count = 1, obj2 out of scope
+// obj.release(); // ref count = 0, object destroyed
+
// Notes on usage:
// 1. Virtual inherit from RefCount interface in base class if smart pointers
// are going to be defined.