aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xbuild-mac/mailcore2.xcodeproj/project.pbxproj2
-rw-r--r--src/core/abstract/MCMessageHeader.cpp7
-rw-r--r--src/core/basetypes/MCData.cpp7
-rw-r--r--src/core/basetypes/MCObject.cpp19
-rw-r--r--src/core/basetypes/MCObject.h5
-rw-r--r--src/core/basetypes/MCString.cpp21
6 files changed, 38 insertions, 23 deletions
diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj
index 58525de5..7e5b36b9 100755
--- a/build-mac/mailcore2.xcodeproj/project.pbxproj
+++ b/build-mac/mailcore2.xcodeproj/project.pbxproj
@@ -1667,6 +1667,7 @@
C62C6F0516A7E54400737497 /* MCPOPFetchMessagesOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCPOPFetchMessagesOperation.h; sourceTree = "<group>"; };
C62C6F0816A8F57000737497 /* MCIMAPAsyncSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCIMAPAsyncSession.cpp; sourceTree = "<group>"; };
C62C6F0916A8F57700737497 /* MCIMAPAsyncSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCIMAPAsyncSession.h; sourceTree = "<group>"; };
+ C634B7791A723BD1003EE538 /* MCLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCLock.h; sourceTree = "<group>"; };
C63CD67716BDCDD400DB18F1 /* MCAddressDisplay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCAddressDisplay.cpp; sourceTree = "<group>"; };
C63CD67816BDCDD400DB18F1 /* MCAddressDisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCAddressDisplay.h; sourceTree = "<group>"; };
C63CD67916BDCDD400DB18F1 /* MCDateFormatter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCDateFormatter.cpp; sourceTree = "<group>"; };
@@ -2689,6 +2690,7 @@
C64EA6BA169E847800778456 /* MCValue.cpp */,
C64EA6BB169E847800778456 /* MCValue.h */,
C64BB25316FC2AA0000DB34C /* MCValuePrivate.h */,
+ C634B7791A723BD1003EE538 /* MCLock.h */,
);
path = basetypes;
sourceTree = "<group>";
diff --git a/src/core/abstract/MCMessageHeader.cpp b/src/core/abstract/MCMessageHeader.cpp
index bc141424..e65695ca 100644
--- a/src/core/abstract/MCMessageHeader.cpp
+++ b/src/core/abstract/MCMessageHeader.cpp
@@ -6,6 +6,7 @@
#include "MCAddress.h"
#include "MCIterator.h"
#include "MCLibetpan.h"
+#include "MCLock.h"
#include <string.h>
#ifndef _MSC_VER
@@ -76,9 +77,9 @@ void MessageHeader::init(bool generateDate, bool generateMessageID)
}
if (generateMessageID) {
static String * hostname = NULL;
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ static MC_LOCK_TYPE lock = MC_LOCK_INITIAL_VALUE;
- pthread_mutex_lock(&lock);
+ MC_LOCK(&lock);
if (hostname == NULL) {
char name[MAX_HOSTNAME];
int r;
@@ -94,7 +95,7 @@ void MessageHeader::init(bool generateDate, bool generateMessageID)
hostname = new String("localhost");
}
}
- pthread_mutex_unlock(&lock);
+ MC_UNLOCK(&lock);
String * messageID = new String();
messageID->appendString(String::uuidString());
diff --git a/src/core/basetypes/MCData.cpp b/src/core/basetypes/MCData.cpp
index 170ce927..8b689036 100644
--- a/src/core/basetypes/MCData.cpp
+++ b/src/core/basetypes/MCData.cpp
@@ -26,6 +26,7 @@
#include "MCHashMap.h"
#include "MCBase64.h"
#include "MCSet.h"
+#include "MCLock.h"
#define MCDATA_DEFAULT_CHARSET "iso-8859-1"
@@ -205,10 +206,10 @@ String * Data::stringWithCharset(const char * charset)
static bool isHintCharsetValid(String * hintCharset)
{
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ static MC_LOCK_TYPE lock = MC_LOCK_INITIAL_VALUE;
static Set * knownCharset = NULL;
- pthread_mutex_lock(&lock);
+ MC_LOCK(&lock);
if (knownCharset == NULL) {
knownCharset = new Set();
@@ -265,7 +266,7 @@ static bool isHintCharsetValid(String * hintCharset)
}
#endif
}
- pthread_mutex_unlock(&lock);
+ MC_UNLOCK(&lock);
if (hintCharset != NULL) {
hintCharset = normalizeCharset(hintCharset);
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);
diff --git a/src/core/basetypes/MCObject.h b/src/core/basetypes/MCObject.h
index 95446f61..83d6c1a7 100644
--- a/src/core/basetypes/MCObject.h
+++ b/src/core/basetypes/MCObject.h
@@ -5,6 +5,7 @@
#include <pthread.h>
#if __APPLE__
#include <dispatch/dispatch.h>
+#include <libkern/OSAtomic.h>
#endif
#include <MailCore/MCUtils.h>
@@ -56,7 +57,11 @@ namespace mailcore {
public: // private
private:
+#if __APPLE__
+ OSSpinLock mLock;
+#else
pthread_mutex_t mLock;
+#endif
int mCounter;
void init();
static void initObjectConstructors();
diff --git a/src/core/basetypes/MCString.cpp b/src/core/basetypes/MCString.cpp
index a2d9b17c..213d5e5f 100644
--- a/src/core/basetypes/MCString.cpp
+++ b/src/core/basetypes/MCString.cpp
@@ -39,6 +39,7 @@
#include "MCBase64.h"
#include "MCIterator.h"
#include "ConvertUTF.h"
+#include "MCLock.h"
#if defined(_MSC_VER)
#define PATH_SEPARATOR_CHAR '\\'
@@ -1672,9 +1673,9 @@ static void returnToLineAtBeginningOfBlock(struct parserState * state)
static Set * blockElements(void)
{
static Set * elements = NULL;
- pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ MC_LOCK_TYPE lock = MC_LOCK_INITIAL_VALUE;
- pthread_mutex_lock(&lock);
+ MC_LOCK(&lock);
if (elements == NULL) {
elements = new Set();
elements->addObject(MCSTR("address"));
@@ -1705,7 +1706,7 @@ static Set * blockElements(void)
elements->addObject(MCSTR("tr"));
elements->addObject(MCSTR("td"));
}
- pthread_mutex_unlock(&lock);
+ MC_UNLOCK(&lock);
return elements;
}
@@ -1956,9 +1957,9 @@ static void commentParsed(void * ctx, const xmlChar * value)
void initializeLibXML()
{
static bool initDone = false;
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ static MC_LOCK_TYPE lock = MC_LOCK_INITIAL_VALUE;
- pthread_mutex_lock(&lock);
+ MC_LOCK(&lock);
if (!initDone) {
initDone = true;
xmlInitParser();
@@ -1968,7 +1969,7 @@ void initializeLibXML()
xmlSetStructuredErrorFunc(xmlGenericErrorContext,
&structuredError);
}
- pthread_mutex_unlock(&lock);
+ MC_UNLOCK(&lock);
}
String * String::flattenHTMLAndShowBlockquoteAndLink(bool showBlockquote, bool showLink)
@@ -2342,7 +2343,7 @@ String * String::substringWithRange(Range range)
}
static chash * uniquedStringHash = NULL;
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static MC_LOCK_TYPE lock = MC_LOCK_INITIAL_VALUE;
static void initUniquedStringHash()
{
@@ -2359,17 +2360,17 @@ String * String::uniquedStringWithUTF8Characters(const char * UTF8Characters)
pthread_once(&once, initUniquedStringHash);
key.data = (void *) UTF8Characters;
key.len = (unsigned int) strlen(UTF8Characters);
- pthread_mutex_lock(&lock);
+ MC_LOCK(&lock);
r = chash_get(uniquedStringHash, &key, &value);
if (r == 0) {
- pthread_mutex_unlock(&lock);
+ MC_UNLOCK(&lock);
return (String *) value.data;
}
else {
value.data = new String(UTF8Characters);
value.len = 0;
chash_set(uniquedStringHash, &key, &value, NULL);
- pthread_mutex_unlock(&lock);
+ MC_UNLOCK(&lock);
return (String *) value.data;
}
}