зеркало из https://github.com/mozilla/gecko-dev.git
thread safety comes to nsRange
This commit is contained in:
Родитель
e5e54d70ff
Коммит
a79218c7e4
|
@ -45,6 +45,7 @@ static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
|||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||
|
||||
PRMonitor* nsRange::mMonitor = nsnull;
|
||||
nsVoidArray* nsRange::mStartAncestors = nsnull;
|
||||
nsVoidArray* nsRange::mEndAncestors = nsnull;
|
||||
nsVoidArray* nsRange::mStartAncestorOffsets = nsnull;
|
||||
|
@ -52,6 +53,19 @@ nsVoidArray* nsRange::mEndAncestorOffsets = nsnull;
|
|||
|
||||
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
|
||||
|
||||
|
||||
/******************************************************
|
||||
* stack based utilty class for managing monitor
|
||||
******************************************************/
|
||||
|
||||
class nsAutoRangeLock
|
||||
{
|
||||
public:
|
||||
nsAutoRangeLock() { nsRange::Lock(); }
|
||||
~nsAutoRangeLock() { nsRange::Unlock(); }
|
||||
};
|
||||
|
||||
|
||||
/******************************************************
|
||||
* non members
|
||||
******************************************************/
|
||||
|
@ -455,7 +469,8 @@ PRBool nsRange::IsIncreasing(nsIDOMNode* aStartN, PRInt32 aStartOffset,
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// XXX - therad safety - need locks around here to end of routine
|
||||
// thread safety - need locks around here to end of routine to protect use of static members
|
||||
nsAutoRangeLock lock;
|
||||
|
||||
// lazy allocation of static arrays
|
||||
if (!mStartAncestors)
|
||||
|
@ -1151,7 +1166,7 @@ nsresult nsRange::DeleteContents()
|
|||
while (cN && (NS_COMFALSE == iter->IsDone()))
|
||||
{
|
||||
// if node is not an ancestor of start node, delete it
|
||||
if (mStartAncestors->IndexOf(NS_STATIC_CAST(void*,cN)) == -1)
|
||||
if (startAncestorList.IndexOf(NS_STATIC_CAST(void*,cN)) == -1)
|
||||
{
|
||||
deleteList.AppendElement(NS_STATIC_CAST(void*,cN));
|
||||
}
|
||||
|
@ -1922,3 +1937,25 @@ nsRange::SetScriptObject(void *aScriptObject)
|
|||
}
|
||||
|
||||
// END nsIScriptContextOwner interface implementations
|
||||
|
||||
nsresult
|
||||
nsRange::Lock()
|
||||
{
|
||||
if (!mMonitor)
|
||||
mMonitor = ::PR_NewMonitor();
|
||||
|
||||
if (mMonitor)
|
||||
PR_EnterMonitor(mMonitor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsRange::Unlock()
|
||||
{
|
||||
if (mMonitor)
|
||||
PR_ExitMonitor(mMonitor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "prmon.h"
|
||||
|
||||
class nsVoidArray;
|
||||
|
||||
|
@ -111,10 +112,11 @@ public:
|
|||
PRInt32 mEndOffset;
|
||||
nsCOMPtr<nsIDOMNode> mStartParent;
|
||||
nsCOMPtr<nsIDOMNode> mEndParent;
|
||||
static nsVoidArray *mStartAncestors; // just keeping these around to avoid reallocing the arrays.
|
||||
static PRMonitor *mMonitor; // monitor to protect the following statics
|
||||
static nsVoidArray *mStartAncestors; // just keeping these static to avoid reallocing the arrays.
|
||||
static nsVoidArray *mEndAncestors; // the contents of these arrays are discarded across calls.
|
||||
static nsVoidArray *mStartAncestorOffsets; //
|
||||
static nsVoidArray *mEndAncestorOffsets; // XXX - thread safety alert - need to lock usage of these
|
||||
static nsVoidArray *mStartAncestorOffsets; // this also makes nsRange objects lighter weight.
|
||||
static nsVoidArray *mEndAncestorOffsets; //
|
||||
|
||||
// no copy's or assigns
|
||||
nsRange(const nsRange&);
|
||||
|
@ -129,6 +131,8 @@ public:
|
|||
static nsresult GetDOMNodeFromContent(nsIContent* inContentNode, nsCOMPtr<nsIDOMNode>* outDomNode);
|
||||
static nsresult GetContentFromDOMNode(nsIDOMNode* inDomNode, nsCOMPtr<nsIContent>* outContentNode);
|
||||
static nsresult PopRanges(nsIDOMNode* aDestNode, PRInt32 aOffset, nsIContent* aSourceNode);
|
||||
static nsresult Lock();
|
||||
static nsresult Unlock();
|
||||
|
||||
static nsresult CloneSibsAndParents(nsIDOMNode* parentNode,
|
||||
PRInt32 nodeOffset,
|
||||
|
|
|
@ -45,6 +45,7 @@ static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
|||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||
|
||||
PRMonitor* nsRange::mMonitor = nsnull;
|
||||
nsVoidArray* nsRange::mStartAncestors = nsnull;
|
||||
nsVoidArray* nsRange::mEndAncestors = nsnull;
|
||||
nsVoidArray* nsRange::mStartAncestorOffsets = nsnull;
|
||||
|
@ -52,6 +53,19 @@ nsVoidArray* nsRange::mEndAncestorOffsets = nsnull;
|
|||
|
||||
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
|
||||
|
||||
|
||||
/******************************************************
|
||||
* stack based utilty class for managing monitor
|
||||
******************************************************/
|
||||
|
||||
class nsAutoRangeLock
|
||||
{
|
||||
public:
|
||||
nsAutoRangeLock() { nsRange::Lock(); }
|
||||
~nsAutoRangeLock() { nsRange::Unlock(); }
|
||||
};
|
||||
|
||||
|
||||
/******************************************************
|
||||
* non members
|
||||
******************************************************/
|
||||
|
@ -455,7 +469,8 @@ PRBool nsRange::IsIncreasing(nsIDOMNode* aStartN, PRInt32 aStartOffset,
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// XXX - therad safety - need locks around here to end of routine
|
||||
// thread safety - need locks around here to end of routine to protect use of static members
|
||||
nsAutoRangeLock lock;
|
||||
|
||||
// lazy allocation of static arrays
|
||||
if (!mStartAncestors)
|
||||
|
@ -1151,7 +1166,7 @@ nsresult nsRange::DeleteContents()
|
|||
while (cN && (NS_COMFALSE == iter->IsDone()))
|
||||
{
|
||||
// if node is not an ancestor of start node, delete it
|
||||
if (mStartAncestors->IndexOf(NS_STATIC_CAST(void*,cN)) == -1)
|
||||
if (startAncestorList.IndexOf(NS_STATIC_CAST(void*,cN)) == -1)
|
||||
{
|
||||
deleteList.AppendElement(NS_STATIC_CAST(void*,cN));
|
||||
}
|
||||
|
@ -1922,3 +1937,25 @@ nsRange::SetScriptObject(void *aScriptObject)
|
|||
}
|
||||
|
||||
// END nsIScriptContextOwner interface implementations
|
||||
|
||||
nsresult
|
||||
nsRange::Lock()
|
||||
{
|
||||
if (!mMonitor)
|
||||
mMonitor = ::PR_NewMonitor();
|
||||
|
||||
if (mMonitor)
|
||||
PR_EnterMonitor(mMonitor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsRange::Unlock()
|
||||
{
|
||||
if (mMonitor)
|
||||
PR_ExitMonitor(mMonitor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIContent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "prmon.h"
|
||||
|
||||
class nsVoidArray;
|
||||
|
||||
|
@ -111,10 +112,11 @@ public:
|
|||
PRInt32 mEndOffset;
|
||||
nsCOMPtr<nsIDOMNode> mStartParent;
|
||||
nsCOMPtr<nsIDOMNode> mEndParent;
|
||||
static nsVoidArray *mStartAncestors; // just keeping these around to avoid reallocing the arrays.
|
||||
static PRMonitor *mMonitor; // monitor to protect the following statics
|
||||
static nsVoidArray *mStartAncestors; // just keeping these static to avoid reallocing the arrays.
|
||||
static nsVoidArray *mEndAncestors; // the contents of these arrays are discarded across calls.
|
||||
static nsVoidArray *mStartAncestorOffsets; //
|
||||
static nsVoidArray *mEndAncestorOffsets; // XXX - thread safety alert - need to lock usage of these
|
||||
static nsVoidArray *mStartAncestorOffsets; // this also makes nsRange objects lighter weight.
|
||||
static nsVoidArray *mEndAncestorOffsets; //
|
||||
|
||||
// no copy's or assigns
|
||||
nsRange(const nsRange&);
|
||||
|
@ -129,6 +131,8 @@ public:
|
|||
static nsresult GetDOMNodeFromContent(nsIContent* inContentNode, nsCOMPtr<nsIDOMNode>* outDomNode);
|
||||
static nsresult GetContentFromDOMNode(nsIDOMNode* inDomNode, nsCOMPtr<nsIContent>* outContentNode);
|
||||
static nsresult PopRanges(nsIDOMNode* aDestNode, PRInt32 aOffset, nsIContent* aSourceNode);
|
||||
static nsresult Lock();
|
||||
static nsresult Unlock();
|
||||
|
||||
static nsresult CloneSibsAndParents(nsIDOMNode* parentNode,
|
||||
PRInt32 nodeOffset,
|
||||
|
|
Загрузка…
Ссылка в новой задаче