Sophie

Sophie

distrib > Fedora > 13 > i386 > media > updates-src > by-pkgid > e548512dcc847653815f1b7adc710b15 > files > 33

libvmime07-0.7.1-4.fc13.src.rpm

Patch by Zarafa <http://www.zarafa.com/> - workaround a static variable in the smart_ptr class using a
pthread mutex, which fixes multi-threading issues in libvmime.

--- libvmime-0.7.1/vmime/utility/smartPtr.hpp				2005-05-19 19:17:17.000000000 +0200
+++ libvmime-0.7.1/vmime/utility/smartPtr.hpp.threading-remove-static	2009-05-13 15:21:53.276875219 +0200
@@ -20,6 +20,9 @@
 #ifndef VMIME_UTILITY_SMARTPTR_HPP_INCLUDED
 #define VMIME_UTILITY_SMARTPTR_HPP_INCLUDED
 
+// non-portable, but at least not an abi change
+#include <pthread.h>
+static pthread_mutex_t mapLock = PTHREAD_MUTEX_INITIALIZER;
 
 namespace vmime {
 namespace utility {
@@ -108,8 +111,10 @@
 		{
 			if (m_data->refCount == 1)
 			{
+				pthread_mutex_lock(&mapLock);
 				typename MapType::iterator it = sm_map.find(m_data->ptr);
 				if (it != sm_map.end()) sm_map.erase(it);
+				pthread_mutex_unlock(&mapLock);
 
 				delete (m_data->ptr);
 				delete (m_data);
@@ -127,6 +132,8 @@
 	{
 		detach();
 
+		pthread_mutex_lock(&mapLock);
+
 		typename MapType::iterator it = sm_map.find(p);
 
 		if (it != sm_map.end())
@@ -141,6 +148,8 @@
 
 			sm_map.insert(typename MapType::value_type(p, m_data));
 		}
+
+		pthread_mutex_unlock(&mapLock);
 	}
 
 	void attach(const smart_ptr <T>& p)