Missing part of fix for bug 117153, fixing threadsafety problems with shared empty buffer handles. b=120300 r=jag sr=alecf a=blizzard

This commit is contained in:
dbaron%fas.harvard.edu 2002-01-17 00:07:15 +00:00
parent 213c1a45d8
commit 362b589445

View File

@ -81,11 +81,15 @@ XPCReadableJSStringWrapper::BufferHandle(JSBool shared) const
{
if (!mStr) {
// This is a "void" string, so return a shared empty buffer handle.
static char_type null_char = char_type(0);
static shared_buffer_handle_type* sBufferHandle = nsnull;
if (!sBufferHandle) {
sBufferHandle = NS_AllocateContiguousHandleWithData(sBufferHandle,
PRUint32(1), (self_type*)nsnull);
sBufferHandle->AcquireReference();
sBufferHandle = new nsNonDestructingSharedBufferHandle<char_type>(&null_char, &null_char, 1);
sBufferHandle->AcquireReference(); // To avoid the |Destroy|
// mechanism unless threads race to
// set the refcount, in which case
// we'll pull the same trick in
// |Destroy|.
}
return sBufferHandle;
}