aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2016-02-28 12:14:09 -0800
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2016-02-28 12:14:19 -0800
commit74392d0ccd70fd5c859fc879d0dfb60e20f8fd58 (patch)
tree0893478357173d8019affc3a912bff9dba80320e
parenteac836a9858e765e0fb07f1b1f4b325893666fe6 (diff)
Improved thread safety on connectionLogger
-rwxr-xr-xsrc/core/imap/MCIMAPSession.cpp26
-rwxr-xr-xsrc/core/imap/MCIMAPSession.h5
2 files changed, 27 insertions, 4 deletions
diff --git a/src/core/imap/MCIMAPSession.cpp b/src/core/imap/MCIMAPSession.cpp
index 79993ea8..a6c6c21e 100755
--- a/src/core/imap/MCIMAPSession.cpp
+++ b/src/core/imap/MCIMAPSession.cpp
@@ -350,6 +350,7 @@ void IMAPSession::init()
mProgressCallback = NULL;
mProgressItemsCount = 0;
mConnectionLogger = NULL;
+ pthread_mutex_init(&mConnectionLoggerLock, NULL);
mAutomaticConfigurationEnabled = true;
mAutomaticConfigurationDone = false;
mShouldDisconnect = false;
@@ -376,6 +377,7 @@ IMAPSession::~IMAPSession()
MC_SAFE_RELEASE(mDefaultNamespace);
MC_SAFE_RELEASE(mCurrentFolder);
pthread_mutex_destroy(&mIdleLock);
+ pthread_mutex_destroy(&mConnectionLoggerLock);
}
void IMAPSession::setHostname(String * hostname)
@@ -510,13 +512,18 @@ void IMAPSession::items_progress(size_t current, size_t maximum, void * context)
static void logger(mailimap * imap, int log_type, const char * buffer, size_t size, void * context)
{
IMAPSession * session = (IMAPSession *) context;
-
- if (session->connectionLogger() == NULL)
+ session->lockConnectionLogger();
+
+ if (session->connectionLogger() == NULL) {
+ session->unlockConnectionLogger();
return;
+ }
ConnectionLogType type = getConnectionType(log_type);
- if ((int) type == -1)
+ if ((int) type == -1) {
+ session->unlockConnectionLogger();
return;
+ }
bool isBuffer = isBufferFromLogType(log_type);
@@ -529,6 +536,7 @@ static void logger(mailimap * imap, int log_type, const char * buffer, size_t si
else {
session->connectionLogger()->log(session, type, NULL);
}
+ session->unlockConnectionLogger();
}
void IMAPSession::setup()
@@ -3955,7 +3963,9 @@ bool IMAPSession::isDisconnected()
void IMAPSession::setConnectionLogger(ConnectionLogger * logger)
{
+ lockConnectionLogger();
mConnectionLogger = logger;
+ unlockConnectionLogger();
}
ConnectionLogger * IMAPSession::connectionLogger()
@@ -3963,6 +3973,16 @@ ConnectionLogger * IMAPSession::connectionLogger()
return mConnectionLogger;
}
+void IMAPSession::lockConnectionLogger()
+{
+ pthread_mutex_lock(&mConnectionLoggerLock);
+}
+
+void IMAPSession::unlockConnectionLogger()
+{
+ pthread_mutex_unlock(&mConnectionLoggerLock);
+}
+
String * IMAPSession::htmlRendering(IMAPMessage * message, String * folder, ErrorCode * pError)
{
HTMLRendererIMAPDataCallback * dataCallback = new HTMLRendererIMAPDataCallback(this, message->uid());
diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h
index effa0fe8..5f516ff5 100755
--- a/src/core/imap/MCIMAPSession.h
+++ b/src/core/imap/MCIMAPSession.h
@@ -217,7 +217,9 @@ namespace mailcore {
virtual void resetAutomaticConfigurationDone();
virtual void applyCapabilities(IndexSet * capabilities);
virtual IndexSet * storedCapabilities();
-
+ virtual void lockConnectionLogger();
+ virtual void unlockConnectionLogger();
+
private:
String * mHostname;
unsigned int mPort;
@@ -264,6 +266,7 @@ namespace mailcore {
IMAPProgressCallback * mProgressCallback;
unsigned int mProgressItemsCount;
ConnectionLogger * mConnectionLogger;
+ pthread_mutex_t mConnectionLoggerLock;
bool mAutomaticConfigurationEnabled;
bool mAutomaticConfigurationDone;
bool mShouldDisconnect;