Add thread safety for std::shared_object_ptr

This commit is contained in:
Eduardo Bart 2013-03-04 10:47:07 -03:00
parent 3980f859b7
commit bdbe065c23
2 changed files with 13 additions and 1 deletions

View File

@ -281,6 +281,10 @@ else()
set(framework_LIBRARIES ${framework_LIBRARIES} ${SYSTEM_LIBRARIES}) set(framework_LIBRARIES ${framework_LIBRARIES} ${SYSTEM_LIBRARIES})
endif() endif()
if(FRAMEWORK_THREAD_SAFE)
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DTHREAD_SAFE)
endif()
if(FRAMEWORK_GRAPHICS) if(FRAMEWORK_GRAPHICS)
set(OPENGLES "OFF" CACHE "Use OpenGL ES 1.0 or 2.0 (for mobiles devices)" STRING) set(OPENGLES "OFF" CACHE "Use OpenGL ES 1.0 or 2.0 (for mobiles devices)" STRING)
if(OPENGLES STREQUAL "2.0") if(OPENGLES STREQUAL "2.0")

View File

@ -28,12 +28,16 @@
#include <cassert> #include <cassert>
#include <ostream> #include <ostream>
#ifdef THREAD_SAFE
#include <atomic>
#endif
namespace stdext { namespace stdext {
template<class T> template<class T>
class shared_object_ptr; class shared_object_ptr;
typedef unsigned int refcount_t; typedef unsigned long refcount_t;
class shared_object class shared_object
{ {
@ -49,7 +53,11 @@ public:
template<typename T> stdext::shared_object_ptr<T> const_self_cast() { return stdext::shared_object_ptr<T>(const_cast<T*>(this)); } template<typename T> stdext::shared_object_ptr<T> const_self_cast() { return stdext::shared_object_ptr<T>(const_cast<T*>(this)); }
private: private:
#ifdef THREAD_SAFE
std::atomic<refcount_t> m_refs;
#else
refcount_t m_refs; refcount_t m_refs;
#endif
}; };
template<class T> template<class T>