diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index 4608e12c77a..bf7ca0ab95e 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -16,6 +16,8 @@ * Reserved. */ +#include "pratom.h" + #include "nsVoidArray.h" #include "nsIDOMDocument.h" @@ -155,9 +157,8 @@ nsEditor::nsEditor() { //initialize member variables here NS_INIT_REFCNT(); - PR_EnterMonitor(GetEditorMonitor()); - gInstanceCount++; - PR_ExitMonitor(GetEditorMonitor()); + + PR_AtomicIncrement(&gInstanceCount); } nsEditor::~nsEditor() @@ -184,6 +185,8 @@ nsEditor::~nsEditor() InsertTextTxn::ClassShutdown(); IMETextTxn::ClassShutdown(); IMECommitTxn::ClassShutdown(); + + PR_AtomicDecrement(&gInstanceCount); } diff --git a/mozilla/editor/base/nsEditor.h b/mozilla/editor/base/nsEditor.h index 240caa4a89a..e6301b2629c 100644 --- a/mozilla/editor/base/nsEditor.h +++ b/mozilla/editor/base/nsEditor.h @@ -21,7 +21,6 @@ #include "nsCOMPtr.h" #include "nsWeakPtr.h" -#include "prmon.h" #include "nsIEditor.h" #include "nsIEditorIMESupport.h" @@ -66,9 +65,6 @@ class AddStyleSheetTxn; class RemoveStyleSheetTxn; class nsFileSpec; -//This is the monitor for the editor. -PRMonitor *GetEditorMonitor(); - /** implementation of an editor object. it will be the controler/focal point * for the main editor services. i.e. the GUIManager, publishing, transaction diff --git a/mozilla/editor/base/nsEditorRegistration.cpp b/mozilla/editor/base/nsEditorRegistration.cpp index ccc98263aa4..c709ce07bb4 100644 --- a/mozilla/editor/base/nsEditorRegistration.cpp +++ b/mozilla/editor/base/nsEditorRegistration.cpp @@ -304,6 +304,8 @@ nsEditorModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) if (!okToUnload) { return NS_ERROR_INVALID_POINTER; } + // we might want to check nsEditor::gInstanceCount == 0 and count + // factory locks here one day. *okToUnload = PR_FALSE; return NS_ERROR_FAILURE; } @@ -336,20 +338,3 @@ extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, gModule = m; // WARNING: Weak Reference return rv; } - -//!!!!!! This is obsolete is needs to be removed. It should be removed after the calls to -//!!!!!! it are removed. - -//if more than one person asks for the monitor at the same time for the FIRST time, we are screwed -PRMonitor *GetEditorMonitor() -{ - static PRMonitor *ns_editlock = nsnull; - if (nsnull == ns_editlock) - { - ns_editlock = (PRMonitor *)1; //how long will the next line take? lets cut down on the chance of reentrancy - ns_editlock = PR_NewMonitor(); - } - else if ((PRMonitor *)1 == ns_editlock) - return GetEditorMonitor(); - return ns_editlock; -} diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 4608e12c77a..bf7ca0ab95e 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -16,6 +16,8 @@ * Reserved. */ +#include "pratom.h" + #include "nsVoidArray.h" #include "nsIDOMDocument.h" @@ -155,9 +157,8 @@ nsEditor::nsEditor() { //initialize member variables here NS_INIT_REFCNT(); - PR_EnterMonitor(GetEditorMonitor()); - gInstanceCount++; - PR_ExitMonitor(GetEditorMonitor()); + + PR_AtomicIncrement(&gInstanceCount); } nsEditor::~nsEditor() @@ -184,6 +185,8 @@ nsEditor::~nsEditor() InsertTextTxn::ClassShutdown(); IMETextTxn::ClassShutdown(); IMECommitTxn::ClassShutdown(); + + PR_AtomicDecrement(&gInstanceCount); } diff --git a/mozilla/editor/libeditor/base/nsEditor.h b/mozilla/editor/libeditor/base/nsEditor.h index 240caa4a89a..e6301b2629c 100644 --- a/mozilla/editor/libeditor/base/nsEditor.h +++ b/mozilla/editor/libeditor/base/nsEditor.h @@ -21,7 +21,6 @@ #include "nsCOMPtr.h" #include "nsWeakPtr.h" -#include "prmon.h" #include "nsIEditor.h" #include "nsIEditorIMESupport.h" @@ -66,9 +65,6 @@ class AddStyleSheetTxn; class RemoveStyleSheetTxn; class nsFileSpec; -//This is the monitor for the editor. -PRMonitor *GetEditorMonitor(); - /** implementation of an editor object. it will be the controler/focal point * for the main editor services. i.e. the GUIManager, publishing, transaction diff --git a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp index ccc98263aa4..c709ce07bb4 100644 --- a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp +++ b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp @@ -304,6 +304,8 @@ nsEditorModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) if (!okToUnload) { return NS_ERROR_INVALID_POINTER; } + // we might want to check nsEditor::gInstanceCount == 0 and count + // factory locks here one day. *okToUnload = PR_FALSE; return NS_ERROR_FAILURE; } @@ -336,20 +338,3 @@ extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, gModule = m; // WARNING: Weak Reference return rv; } - -//!!!!!! This is obsolete is needs to be removed. It should be removed after the calls to -//!!!!!! it are removed. - -//if more than one person asks for the monitor at the same time for the FIRST time, we are screwed -PRMonitor *GetEditorMonitor() -{ - static PRMonitor *ns_editlock = nsnull; - if (nsnull == ns_editlock) - { - ns_editlock = (PRMonitor *)1; //how long will the next line take? lets cut down on the chance of reentrancy - ns_editlock = PR_NewMonitor(); - } - else if ((PRMonitor *)1 == ns_editlock) - return GetEditorMonitor(); - return ns_editlock; -}