aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes/MCObject.cpp
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2015-01-23 00:46:41 -0800
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2015-01-23 00:46:41 -0800
commit2bab15f431bec4ba5f10238e6f578ab2653ea675 (patch)
tree3dd78f995fb1f801e3f57fc019da1f8200c244ab /src/core/basetypes/MCObject.cpp
parentd45ce14d841e6555bf0b524cee12aa111155ffab (diff)
Use spinlock
Diffstat (limited to 'src/core/basetypes/MCObject.cpp')
-rw-r--r--src/core/basetypes/MCObject.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/core/basetypes/MCObject.cpp b/src/core/basetypes/MCObject.cpp
index 3034c791..bbcddb2f 100644
--- a/src/core/basetypes/MCObject.cpp
+++ b/src/core/basetypes/MCObject.cpp
@@ -20,6 +20,7 @@
#include "MCMainThread.h"
#include "MCLog.h"
#include "MCHashMap.h"
+#include "MCLock.h"
using namespace mailcore;
@@ -36,24 +37,28 @@ Object::~Object()
void Object::init()
{
+#if __APPLE__
+ mLock = OS_SPINLOCK_INIT;
+#else
pthread_mutex_init(&mLock, NULL);
+#endif
mCounter = 1;
}
int Object::retainCount()
{
- pthread_mutex_lock(&mLock);
+ MC_LOCK(&mLock);
int value = mCounter;
- pthread_mutex_unlock(&mLock);
+ MC_UNLOCK(&mLock);
return value;
}
Object * Object::retain()
{
- pthread_mutex_lock(&mLock);
+ MC_LOCK(&mLock);
mCounter ++;
- pthread_mutex_unlock(&mLock);
+ MC_UNLOCK(&mLock);
return this;
}
@@ -61,7 +66,7 @@ void Object::release()
{
bool shouldRelease = false;
- pthread_mutex_lock(&mLock);
+ MC_LOCK(&mLock);
mCounter --;
if (mCounter == 0) {
shouldRelease = true;
@@ -70,8 +75,8 @@ void Object::release()
MCLog("release too much %p %s", this, MCUTF8(className()));
MCAssert(0);
}
- pthread_mutex_unlock(&mLock);
-
+ MC_UNLOCK(&mLock);
+
if (shouldRelease && !zombieEnabled) {
//int status;
//char * unmangled = abi::__cxa_demangle(typeid(* this).name(), NULL, NULL, &status);