fix addrbook part of bug 647000, remove use of nsAutoLock, r=neil
authorIan Neal <iann_bugzilla@blueyonder.co.uk>
Thu, 07 Apr 2011 07:04:48 -0700
changeset 7518 283cf841daac94fade5f350f27533999276f5fc4
parent 7517 f8f7eaacaf0fffbe6e8d4efaf74be073b9ef3d52
child 7519 d8a5c55ca78bb68eafd625469e2bf86c3172ca94
push id1
push userhg
push dateTue, 08 Jul 2014 14:20:55 +0000
treeherdercomm-esr31@1665b2be5642 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs647000
fix addrbook part of bug 647000, remove use of nsAutoLock, r=neil
mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp
mailnews/addrbook/src/nsAbLDAPChangeLogQuery.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.h
mailnews/addrbook/src/nsAbLDAPDirectoryModify.cpp
mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
mailnews/addrbook/src/nsAbLDAPListenerBase.h
mailnews/addrbook/src/nsAbRDFDataSource.cpp
mailnews/addrbook/src/nsAbRDFDataSource.h
mailnews/addrbook/src/nsAbWinHelper.cpp
mailnews/addrbook/src/nsAbWinHelper.h
mailnews/addrbook/src/nsMapiAddressBook.cpp
mailnews/addrbook/src/nsWabAddressBook.cpp
--- a/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp
@@ -44,17 +44,16 @@
 #include "nsILDAPMessage.h"
 #include "nsIAbCard.h"
 #include "nsIAddrBookSession.h"
 #include "nsAbBaseCID.h"
 #include "nsAbUtils.h"
 #include "nsAbMDBCard.h"
 #include "nsAbLDAPCard.h"
 #include "nsProxiedService.h"
-#include "nsAutoLock.h"
 #include "nsIAuthPrompt.h"
 #include "nsIStringBundle.h"
 #include "nsIWindowWatcher.h"
 #include "nsUnicharUtils.h"
 #include "plstr.h"
 #include "nsILDAPErrors.h"
 #include "prmem.h"
 
--- a/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.cpp
@@ -38,17 +38,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #include "nsCOMPtr.h"
 #include "nsAbLDAPChangeLogQuery.h"
 #include "nsAbLDAPReplicationService.h"
 #include "nsAbLDAPChangeLogData.h"
-#include "nsAutoLock.h"
 #include "nsAbUtils.h"
 #include "prprf.h"
 #include "nsDirPrefs.h"
 #include "nsAbBaseCID.h"
 
 
 // The tables below were originally in nsAbLDAPProperties.cpp, which has since
 // gone away.
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
@@ -44,17 +44,16 @@
 #include "nsAbLDAPDirectory.h"
 
 #include "nsAbQueryStringToExpression.h"
 
 #include "nsAbBaseCID.h"
 #include "nsIAbManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
-#include "nsAutoLock.h"
 #include "nsNetCID.h"
 #include "nsIIOService.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIAbLDAPAttributeMap.h"
 #include "nsIAbMDBDirectory.h"
 #include "nsILDAPURL.h"
@@ -69,29 +68,29 @@
 #include "nsArrayUtils.h"
 #include "nsIPrefService.h"
 #include "nsIMsgAccountManager.h"
 #include "nsMsgBaseCID.h"
 #include "nsMsgUtils.h"
 
 #define kDefaultMaxHits 100
 
+using namespace mozilla;
+
 nsAbLDAPDirectory::nsAbLDAPDirectory() :
   nsAbDirectoryRDFResource(),
   mPerformingQuery(PR_FALSE),
   mContext(0),
-  mLock(0)
+  mLock("nsAbLDAPDirectory.mLock")
 {
   mCache.Init();
 }
 
 nsAbLDAPDirectory::~nsAbLDAPDirectory()
 {
-  if (mLock)
-    PR_DestroyLock (mLock);
 }
 
 NS_IMPL_ISUPPORTS_INHERITED3(nsAbLDAPDirectory, nsAbDirectoryRDFResource,
                              nsIAbDirectory, nsIAbDirSearchListener,
                              nsIAbLDAPDirectory)
 
 NS_IMETHODIMP nsAbLDAPDirectory::GetPropertiesChromeURI(nsACString &aResult)
 {
@@ -114,20 +113,17 @@ NS_IMETHODIMP nsAbLDAPDirectory::Init(co
   else
     m_DirPrefId = Substring(uri, kLDAPDirectoryRootLen, searchCharLocation - kLDAPDirectoryRootLen);
 
   return nsAbDirectoryRDFResource::Init(aURI);
 }
 
 nsresult nsAbLDAPDirectory::Initiate()
 {
-  if (!mLock)
-    mLock = PR_NewLock();
-
-  return mLock ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+  return NS_OK;
 }
 
 /* 
  *
  * nsIAbDirectory methods
  *
  */
 
@@ -205,17 +201,17 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetIsQu
 }
 
 NS_IMETHODIMP nsAbLDAPDirectory::HasCard(nsIAbCard* card, PRBool* hasCard)
 {
   nsresult rv = Initiate ();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Enter lock
-  nsAutoLock lock (mLock);
+  MutexAutoLock lock (mLock);
 
   *hasCard = mCache.Get(card, nsnull);
   if (!*hasCard && mPerformingQuery)
     return NS_ERROR_NOT_AVAILABLE;
 
   return NS_OK;
 }
 
@@ -359,31 +355,31 @@ NS_IMETHODIMP nsAbLDAPDirectory::StartSe
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // Perform the query
     rv = mDirectoryQuery->DoQuery(this, arguments, this, maxHits, 0, &mContext);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Enter lock
-    nsAutoLock lock(mLock);
+    MutexAutoLock lock(mLock);
     mPerformingQuery = PR_TRUE;
     mCache.Clear();
 
     return rv;
 }  
 
 NS_IMETHODIMP nsAbLDAPDirectory::StopSearch ()
 {
   nsresult rv = Initiate();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Enter lock
   {
-    nsAutoLock lockGuard(mLock);
+    MutexAutoLock lockGuard(mLock);
     if (!mPerformingQuery)
       return NS_OK;
     mPerformingQuery = PR_FALSE;
   }
   // Exit lock
 
   if (!mDirectoryQuery)
     return NS_ERROR_NULL_POINTER;
@@ -396,30 +392,30 @@ NS_IMETHODIMP nsAbLDAPDirectory::StopSea
  * nsAbDirSearchListenerContext methods
  *
  */
 NS_IMETHODIMP nsAbLDAPDirectory::OnSearchFinished(PRInt32 aResult, const nsAString &aErrorMessage)
 {
   nsresult rv = Initiate();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsAutoLock lock(mLock);
+  MutexAutoLock lock(mLock);
   mPerformingQuery = PR_FALSE;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbLDAPDirectory::OnSearchFoundCard(nsIAbCard* card)
 {
   nsresult rv = Initiate();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Enter lock
   {
-    nsAutoLock lock(mLock);
+    MutexAutoLock lock(mLock);
     mCache.Put(card, card);
   }
   // Exit lock
 
   nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   if(NS_SUCCEEDED(rv))
     abManager->NotifyDirectoryItemAdded(this, card);
 
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.h
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.h
@@ -44,16 +44,17 @@
 #include "nsAbDirProperty.h"
 #include "nsAbLDAPDirectoryModify.h"
 #include "nsIAbDirectoryQuery.h"
 #include "nsIAbDirectorySearch.h"
 #include "nsIAbDirSearchListener.h"
 #include "nsIAbLDAPDirectory.h"
 #include "nsIMutableArray.h"
 #include "nsInterfaceHashtable.h"
+#include "mozilla/Mutex.h"
 
 class nsAbLDAPDirectory :
   public nsAbDirectoryRDFResource,    // nsIRDFResource
   public nsAbDirProperty,             // nsIAbDirectory
   public nsAbLDAPDirectoryModify,
   public nsIAbDirectorySearch,
   public nsIAbLDAPDirectory,
   public nsIAbDirSearchListener
@@ -95,15 +96,15 @@ protected:
                            char ***aValues);
 
   PRPackedBool mPerformingQuery;
   PRInt32 mContext;
   PRInt32 mMaxHits;
 
   nsInterfaceHashtable<nsISupportsHashKey, nsIAbCard> mCache;
 
-  PRLock* mLock;
+  mozilla::Mutex mLock;
   nsCOMPtr<nsIAbDirectoryQuery> mDirectoryQuery;
   nsCOMPtr<nsIMutableArray> mSearchServerControls;
   nsCOMPtr<nsIMutableArray> mSearchClientControls;
 };
 
 #endif
--- a/mailnews/addrbook/src/nsAbLDAPDirectoryModify.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectoryModify.cpp
@@ -32,31 +32,32 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbLDAPDirectoryModify.h"
-#include "nsAutoLock.h"
 #include "nsILDAPMessage.h"
 #include "nsILDAPConnection.h"
 #include "nsILDAPErrors.h"
 #include "nsILDAPModification.h"
 #include "nsIServiceManager.h"
 #include "nsIProxyObjectManager.h"
 #include "nsIAbLDAPDirectory.h"
 #include "nsIMutableArray.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsXPCOMCIDInternal.h"
 
 #include <stdio.h>
 
+using namespace mozilla;
+
 class nsAbModifyLDAPMessageListener : public nsAbLDAPListenerBase
 {
 public:
   NS_DECL_ISUPPORTS
 
   nsAbModifyLDAPMessageListener(const PRInt32 type,
                                 const nsACString &cardDN,
                                 nsIArray* modArray,
@@ -132,17 +133,17 @@ nsAbModifyLDAPMessageListener::~nsAbModi
 {
 }
 
 nsresult nsAbModifyLDAPMessageListener::Cancel ()
 {
   nsresult rv = Initiate();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsAutoLock lock(mLock);
+  MutexAutoLock lock(mLock);
 
   if (mFinished || mCanceled)
     return NS_OK;
 
   mCanceled = PR_TRUE;
 
   return NS_OK;
 }
@@ -155,17 +156,17 @@ NS_IMETHODIMP nsAbModifyLDAPMessageListe
   PRInt32 messageType;
   rv = aMessage->GetType(&messageType);
   NS_ENSURE_SUCCESS(rv, rv);
   
   PRBool cancelOperation = PR_FALSE;
 
   // Enter lock
   {
-    nsAutoLock lock (mLock);
+    MutexAutoLock lock (mLock);
 
     if (mFinished)
       return NS_OK;
 
     // for these messages, no matter the outcome, we're done
     if ((messageType == nsILDAPMessage::RES_ADD) || 
         (messageType == nsILDAPMessage::RES_DELETE) ||
         (messageType == nsILDAPMessage::RES_MODIFY))
--- a/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
@@ -46,26 +46,27 @@
 #include "nsILDAPMessage.h"
 #include "nsILDAPErrors.h"
 #include "nsILDAPOperation.h"
 #include "nsIAbLDAPAttributeMap.h"
 #include "nsIAbLDAPCard.h"
 #include "nsAbUtils.h"
 #include "nsAbBaseCID.h"
 #include "nsStringGlue.h"
-#include "nsAutoLock.h"
 #include "nsIProxyObjectManager.h"
 #include "prprf.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsAbLDAPDirectory.h"
 #include "nsAbLDAPListenerBase.h"
 #include "nsXPCOMCIDInternal.h"
 
+using namespace mozilla;
+
 // nsAbLDAPListenerBase inherits nsILDAPMessageListener
 class nsAbQueryLDAPMessageListener : public nsAbLDAPListenerBase
 {
 public:
   NS_DECL_ISUPPORTS
 
   // Note that the directoryUrl is the details of the ldap directory
   // without any search params or return attributes specified. The searchUrl
@@ -144,17 +145,17 @@ nsAbQueryLDAPMessageListener::~nsAbQuery
 {
 }
 
 nsresult nsAbQueryLDAPMessageListener::Cancel ()
 {
     nsresult rv = Initiate();
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsAutoLock lock(mLock);
+    MutexAutoLock lock(mLock);
 
     if (mFinished || mCanceled)
         return NS_OK;
 
     mCanceled = PR_TRUE;
     if (!mFinished)
       mWaitingForPrevQueryToFinish = PR_TRUE;
 
@@ -169,17 +170,17 @@ NS_IMETHODIMP nsAbQueryLDAPMessageListen
   PRInt32 messageType;
   rv = aMessage->GetType(&messageType);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool cancelOperation = PR_FALSE;
 
   // Enter lock
   {
-    nsAutoLock lock (mLock);
+    MutexAutoLock lock (mLock);
 
     if (mFinished)
       return NS_OK;
 
     if (messageType == nsILDAPMessage::RES_SEARCH_RESULT)
       mFinished = PR_TRUE;
     else if (mCanceled)
     {
--- a/mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
@@ -49,44 +49,40 @@
 #include "nsILDAPErrors.h"
 #include "nsILoginManager.h"
 #include "nsILoginInfo.h"
 #include "nsServiceManagerUtils.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsComponentManagerUtils.h"
 #include "nsMemory.h"
 
+using namespace mozilla;
+
 nsAbLDAPListenerBase::nsAbLDAPListenerBase(nsILDAPURL* url,
                                            nsILDAPConnection* connection,
                                            const nsACString &login,
                                            const PRInt32 timeOut) :
   mDirectoryUrl(url), mConnection(connection), mLogin(login),
   mTimeOut(timeOut), mBound(PR_FALSE), mInitialized(PR_FALSE),
-  mLock(nsnull)
+  mLock("nsAbLDAPListenerBase.mLock")
 {
 }
 
 nsAbLDAPListenerBase::~nsAbLDAPListenerBase()
 {
-  if (mLock)
-    PR_DestroyLock(mLock);
 }
 
 nsresult nsAbLDAPListenerBase::Initiate()
 {
   if (!mConnection || !mDirectoryUrl)
     return NS_ERROR_NULL_POINTER;
 
   if (mInitialized)
     return NS_OK;
 
-  mLock = PR_NewLock();
-  if (!mLock)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   mInitialized = PR_TRUE;
 
   return NS_OK;
 }
 
 // If something fails in this function, we must call InitFailed() so that the
 // derived class (and listener) knows to cancel what its doing as there is
 // a problem.
--- a/mailnews/addrbook/src/nsAbLDAPListenerBase.h
+++ b/mailnews/addrbook/src/nsAbLDAPListenerBase.h
@@ -42,16 +42,17 @@
 #define nsAbLDAPListenerBase_h__
 
 #include "nsCOMPtr.h"
 #include "nsILDAPMessageListener.h"
 #include "nsILDAPURL.h"
 #include "nsILDAPConnection.h"
 #include "nsILDAPOperation.h"
 #include "nsStringGlue.h"
+#include "mozilla/Mutex.h"
 
 class nsAbLDAPListenerBase : public nsILDAPMessageListener
 {
 public:
   // Note that the directoryUrl is the details of the ldap directory
   // without any search params or attributes specified.
   nsAbLDAPListenerBase(nsILDAPURL* directoryUrl = nsnull,
                        nsILDAPConnection* connection = nsnull,
@@ -76,12 +77,12 @@ protected:
   nsCOMPtr<nsILDAPOperation> mOperation;        // current ldap op
   nsILDAPConnection* mConnection;
   nsCString mLogin;
   nsCString mSaslMechanism;
   PRInt32 mTimeOut;
   PRBool mBound;
   PRBool mInitialized;
 
-  PRLock* mLock;
+  mozilla::Mutex mLock;
 };
 
 #endif
--- a/mailnews/addrbook/src/nsAbRDFDataSource.cpp
+++ b/mailnews/addrbook/src/nsAbRDFDataSource.cpp
@@ -45,22 +45,23 @@
 #include "rdf.h"
 #include "nsIRDFService.h"
 #include "nsRDFCID.h"
 #include "nsIRDFNode.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIProxyObjectManager.h"
 
 #include "nsCOMPtr.h"
-#include "nsAutoLock.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOMCIDInternal.h"
 
+using namespace mozilla;
+
 // this is used for notification of observers using nsVoidArray
 typedef struct _nsAbRDFNotification {
   nsIRDFDataSource *datasource;
   nsIRDFResource *subject;
   nsIRDFResource *property;
   nsIRDFNode *object;
 } nsAbRDFNotification;
 
@@ -178,25 +179,19 @@ nsresult nsAbRDFDataSource::NotifyObserv
   nsIRDFResource *property,
   nsIRDFNode *object,
   PRBool assert,
   PRBool change)
 {
   NS_ASSERTION(!(change && assert),
                  "Can't change and assert at the same time!\n");
 
-  if(!mLock)
-  {
-    NS_ERROR("Error in AutoLock resource in nsAbRDFDataSource::NotifyObservers()");
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
   nsresult rv;
 
-  nsAutoLock lockGuard (mLock);
+  MutexAutoLock lockGuard (mLock);
 
   /*
    * TODO
    * Is the main thread always guaranteed to be
    * the UI thread?
    *
    * Note that this also binds the data source
    * to the UI which is supposedly the only
@@ -246,25 +241,22 @@ nsresult nsAbRDFDataSource::NotifyProper
   nsCOMPtr<nsIRDFNode> newValueNode;
   createNode(newValue, getter_AddRefs(newValueNode));
   NotifyObservers(resource, propertyResource, newValueNode, PR_FALSE, PR_TRUE);
   return NS_OK;
 }
 
 
 nsAbRDFDataSource::nsAbRDFDataSource():
-  mLock(nsnull)
+  mLock("nsAbRDFDataSource.mLock")
 {
-  mLock = PR_NewLock ();
 }
 
 nsAbRDFDataSource::~nsAbRDFDataSource (void)
 {
-  if(mLock)
-    PR_DestroyLock (mLock);
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsAbRDFDataSource)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsAbRDFDataSource)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mObservers)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mProxyObservers)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsAbRDFDataSource)
@@ -360,43 +352,31 @@ NS_IMETHODIMP nsAbRDFDataSource::HasAsse
                             PRBool* hasAssertion)
 {
     *hasAssertion = PR_FALSE;
     return NS_OK;
 }
 
 NS_IMETHODIMP nsAbRDFDataSource::AddObserver(nsIRDFObserver* observer)
 {
-  if(!mLock)
-  {
-    NS_ERROR("Error in AutoLock resource in nsAbRDFDataSource::AddObservers()");
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
   // Lock the whole method
-  nsAutoLock lockGuard (mLock);
+  MutexAutoLock lockGuard (mLock);
 
   // Do not add if already present
   if (mObservers.IndexOf(observer) >= 0)
     return NS_OK;
 
   mObservers.AppendObject(observer);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbRDFDataSource::RemoveObserver(nsIRDFObserver* observer)
 {
-  if(!mLock)
-  {
-    NS_ERROR("Error in AutoLock resource in nsAbRDFDataSource::RemoveObservers()");
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
   // Lock the whole method
-  nsAutoLock lockGuard (mLock);
+  MutexAutoLock lockGuard (mLock);
   PRInt32 index = mObservers.IndexOf(observer);
   if (index >= 0)
   {
     mObservers.RemoveObjectAt(index);
     mProxyObservers.RemoveObjectAt(index);
   }
 
   return NS_OK;
--- a/mailnews/addrbook/src/nsAbRDFDataSource.h
+++ b/mailnews/addrbook/src/nsAbRDFDataSource.h
@@ -39,16 +39,17 @@
 #define nsAbRDFDataSource_h__
 
 #include "nsCOMPtr.h"
 #include "nsIRDFDataSource.h"
 #include "nsIRDFService.h"
 #include "nsCOMArray.h"
 #include "nsStringGlue.h"
 #include "nsCycleCollectionParticipant.h"
+#include "mozilla/Mutex.h"
 
 /**
  * The addressbook data source.
  */
 class nsAbRDFDataSource : public nsIRDFDataSource
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@@ -85,12 +86,12 @@ protected:
 
   static PRBool assertEnumFunc(nsIRDFObserver *aObserver, void *aData);
   static PRBool unassertEnumFunc(nsIRDFObserver *aObserver, void *aData);
   static PRBool changeEnumFunc(nsIRDFObserver *aObserver, void *aData);
 
 private:
   nsCOMArray<nsIRDFObserver> mObservers;
   nsCOMArray<nsIRDFObserver> mProxyObservers;
-  PRLock* mLock;
+  mozilla::Mutex mLock;
 };
 
 #endif
--- a/mailnews/addrbook/src/nsAbWinHelper.cpp
+++ b/mailnews/addrbook/src/nsAbWinHelper.cpp
@@ -259,24 +259,27 @@ void nsMapiEntryArray::CleanUp(void)
 {
     if (mEntries != NULL) { 
         delete [] mEntries ;
         mEntries = NULL ;
         mNbEntries = 0 ;
     }
 }
 
+using namespace mozilla;
+
 PRUint32 nsAbWinHelper::mEntryCounter = 0 ;
+Mutex nsAbWinHelper::mMutex("nsAbWinHelper.mMutex");
+
 // There seems to be a deadlock/auto-destruction issue
 // in MAPI when multiple threads perform init/release 
 // operations at the same time. So I've put a mutex
 // around both the initialize process and the destruction
 // one. I just hope the rest of the calls don't need the 
 // same protection (MAPI is supposed to be thread-safe).
-PRLock *nsAbWinHelper::mMutex = PR_NewLock() ;
 
 nsAbWinHelper::nsAbWinHelper(void)
 : mAddressBook(NULL), mLastError(S_OK)
 {
     MOZ_COUNT_CTOR(nsAbWinHelper) ;
 }
 
 nsAbWinHelper::~nsAbWinHelper(void)
--- a/mailnews/addrbook/src/nsAbWinHelper.h
+++ b/mailnews/addrbook/src/nsAbWinHelper.h
@@ -37,16 +37,17 @@
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsAbWinHelper_h___
 #define nsAbWinHelper_h___
 
 #include <windows.h>
 #include <mapix.h>
 
 #include "nsStringGlue.h"
+#include "mozilla/Mutex.h"
  
 struct nsMapiEntry
 {
     ULONG     mByteCount ;
     LPENTRYID mEntryId ;
 
     nsMapiEntry(void) ;
     ~nsMapiEntry(void) ;
@@ -124,17 +125,17 @@ public:
     BOOL GetDefaultContainer(nsMapiEntry& aContainer) ;
     // Is the helper correctly initialised?
     BOOL IsOK(void) const { return mAddressBook != NULL ; }
 
 protected:
     HRESULT mLastError ;
     LPADRBOOK mAddressBook ;
     static PRUint32 mEntryCounter ;
-    static PRLock *mMutex ;
+    static mozilla::Mutex mMutex ;
 
     // Retrieve the contents of a container, with an optional restriction
     BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction, 
                      nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType) ;
     // Retrieve the values of a set of properties on a MAPI object
     BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, 
                            ULONG aNbProperties,
                            LPSPropValue& aValues, ULONG& aValueCount) ;
--- a/mailnews/addrbook/src/nsMapiAddressBook.cpp
+++ b/mailnews/addrbook/src/nsMapiAddressBook.cpp
@@ -31,27 +31,27 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include "nsMapiAddressBook.h"
-#include "nsAutoLock.h"
 
 #include "prlog.h"
 
 #ifdef PR_LOGGING
 static PRLogModuleInfo* gMapiAddressBookLog
     = PR_NewLogModule("nsMapiAddressBookLog");
 #endif
 
 #define PRINTF(args) PR_LOG(gMapiAddressBookLog, PR_LOG_DEBUG, args)
 
+using namespace mozilla;
 
 HMODULE nsMapiAddressBook::mLibrary = NULL ;
 PRInt32 nsMapiAddressBook::mLibUsage = 0 ;
 LPMAPIINITIALIZE nsMapiAddressBook::mMAPIInitialize = NULL ;
 LPMAPIUNINITIALIZE nsMapiAddressBook::mMAPIUninitialize = NULL ;
 LPMAPIALLOCATEBUFFER nsMapiAddressBook::mMAPIAllocateBuffer = NULL ;
 LPMAPIFREEBUFFER nsMapiAddressBook::mMAPIFreeBuffer = NULL ;
 LPMAPILOGONEX nsMapiAddressBook::mMAPILogonEx = NULL ;
@@ -140,26 +140,26 @@ nsMapiAddressBook::nsMapiAddressBook(voi
     BOOL result = Initialize() ;
 
     NS_ASSERTION(result == TRUE, "Couldn't initialize Mapi Helper") ;
     MOZ_COUNT_CTOR(nsMapiAddressBook) ;
 }
 
 nsMapiAddressBook::~nsMapiAddressBook(void)
 {
-    nsAutoLock guard(mMutex) ;
+    MutexAutoLock guard(mMutex) ;
 
     FreeMapiLibrary() ;
     MOZ_COUNT_DTOR(nsMapiAddressBook) ;
 }
 
 BOOL nsMapiAddressBook::Initialize(void)
 {
     if (mAddressBook) { return TRUE ; }
-    nsAutoLock guard(mMutex) ;
+    MutexAutoLock guard(mMutex) ;
 
     if (!LoadMapiLibrary()) {
         PRINTF(("Cannot load library.\n")) ;
         return FALSE ;
     }
     mAddressBook = mRootBook ; 
     return TRUE ;
 }
--- a/mailnews/addrbook/src/nsWabAddressBook.cpp
+++ b/mailnews/addrbook/src/nsWabAddressBook.cpp
@@ -31,26 +31,27 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include "nsWabAddressBook.h"
-#include "nsAutoLock.h"
 #include "prlog.h"
 
 #ifdef PR_LOGGING
 static PRLogModuleInfo* gWabAddressBookLog
     = PR_NewLogModule("nsWabAddressBookLog");
 #endif
 
 #define PRINTF(args) PR_LOG(gWabAddressBookLog, PR_LOG_DEBUG, args)
 
+using namespace mozilla;
+
 HMODULE nsWabAddressBook::mLibrary = NULL ;
 PRInt32 nsWabAddressBook::mLibUsage = 0 ;
 LPWABOPEN nsWabAddressBook::mWABOpen = NULL ;
 LPWABOBJECT nsWabAddressBook::mRootSession = NULL ;
 LPADRBOOK nsWabAddressBook::mRootBook = NULL ;
 
 BOOL nsWabAddressBook::LoadWabLibrary(void)
 {
@@ -97,25 +98,25 @@ nsWabAddressBook::nsWabAddressBook(void)
     BOOL result = Initialize() ;
 
     NS_ASSERTION(result == TRUE, "Couldn't initialize Wab Helper") ;
     MOZ_COUNT_CTOR(nsWabAddressBook) ;
 }
 
 nsWabAddressBook::~nsWabAddressBook(void)
 {
-    nsAutoLock guard(mMutex) ;
+    MutexAutoLock guard(mMutex) ;
     FreeWabLibrary() ;
     MOZ_COUNT_DTOR(nsWabAddressBook) ;
 }
 
 BOOL nsWabAddressBook::Initialize(void)
 {
     if (mAddressBook) { return TRUE ; }
-    nsAutoLock guard(mMutex) ;
+    MutexAutoLock guard(mMutex) ;
 
     if (!LoadWabLibrary()) {
         PRINTF(("Cannot load library.\n")) ;
         return FALSE ;
     }
     mAddressBook = mRootBook ;
     return TRUE ;
 }