From f53c9c41ba836710940564fc91cf7ee10d41ea93 Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Thu, 21 Oct 1999 05:36:21 +0000 Subject: [PATCH] Removal of calls to PR_MumbleMonitor, which were way too heavy-handed for the job. Replaced with PR_AtomicInc/Decrement. part of module sweep, r=morse, pavlov --- editor/base/nsEditor.cpp | 9 ++++++--- editor/base/nsEditor.h | 4 ---- editor/base/nsEditorRegistration.cpp | 19 ++----------------- editor/libeditor/base/nsEditor.cpp | 9 ++++++--- editor/libeditor/base/nsEditor.h | 4 ---- .../libeditor/build/nsEditorRegistration.cpp | 19 ++----------------- 6 files changed, 16 insertions(+), 48 deletions(-) diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 4608e12c77aa..bf7ca0ab95eb 100644 --- a/editor/base/nsEditor.cpp +++ b/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/editor/base/nsEditor.h b/editor/base/nsEditor.h index 240caa4a89a2..e6301b2629ca 100644 --- a/editor/base/nsEditor.h +++ b/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/editor/base/nsEditorRegistration.cpp b/editor/base/nsEditorRegistration.cpp index ccc98263aa49..c709ce07bb42 100644 --- a/editor/base/nsEditorRegistration.cpp +++ b/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/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 4608e12c77aa..bf7ca0ab95eb 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/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/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 240caa4a89a2..e6301b2629ca 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/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/editor/libeditor/build/nsEditorRegistration.cpp b/editor/libeditor/build/nsEditorRegistration.cpp index ccc98263aa49..c709ce07bb42 100644 --- a/editor/libeditor/build/nsEditorRegistration.cpp +++ b/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; -}