Bug 372546 - Mark pipe input/output streams as threadsafe. r=bsmedberg

This commit is contained in:
jwalden%mit.edu 2007-03-25 07:31:45 +00:00
Родитель 9658fa738b
Коммит 9df5416bc3
3 изменённых файлов: 124 добавлений и 10 удалений

Просмотреть файл

@ -1468,4 +1468,63 @@ NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *count, nsIID ***array) \
#define NS_INTERFACE_MAP_END_THREADSAFE NS_IMPL_QUERY_TAIL_GUTS
/**
* Macro to generate nsIClassInfo methods for classes which do not have
* corresponding nsIFactory implementations.
*/
#define NS_IMPL_THREADSAFE_CI(_class) \
NS_IMETHODIMP \
_class::GetInterfaces(PRUint32* _count, nsIID*** _array) \
{ \
return NS_CI_INTERFACE_GETTER_NAME(_class)(_count, _array); \
} \
\
NS_IMETHODIMP \
_class::GetHelperForLanguage(PRUint32 _language, nsISupports** _retval) \
{ \
*_retval = nsnull; \
return NS_OK; \
} \
\
NS_IMETHODIMP \
_class::GetContractID(char** _contractID) \
{ \
*_contractID = nsnull; \
return NS_OK; \
} \
\
NS_IMETHODIMP \
_class::GetClassDescription(char** _classDescription) \
{ \
*_classDescription = nsnull; \
return NS_OK; \
} \
\
NS_IMETHODIMP \
_class::GetClassID(nsCID** _classID) \
{ \
*_classID = nsnull; \
return NS_OK; \
} \
\
NS_IMETHODIMP \
_class::GetImplementationLanguage(PRUint32* _language) \
{ \
*_language = nsIProgrammingLanguage::CPLUSPLUS; \
return NS_OK; \
} \
\
NS_IMETHODIMP \
_class::GetFlags(PRUint32* _flags) \
{ \
*_flags = nsIClassInfo::THREADSAFE; \
return NS_OK; \
} \
\
NS_IMETHODIMP \
_class::GetClassIDNoAlloc(nsCID* _classIDNoAlloc) \
{ \
return NS_ERROR_NOT_AVAILABLE; \
}
#endif

Просмотреть файл

@ -38,6 +38,7 @@
#include "nsIPipe.h"
#include "nsIEventTarget.h"
#include "nsISeekableStream.h"
#include "nsIProgrammingLanguage.h"
#include "nsSegmentedBuffer.h"
#include "nsStreamUtils.h"
#include "nsAutoLock.h"
@ -104,6 +105,7 @@ private:
class nsPipeInputStream : public nsIAsyncInputStream
, public nsISeekableStream
, public nsISearchableInputStream
, public nsIClassInfo
{
public:
// since this class will be allocated as a member of the pipe, we do not
@ -117,6 +119,7 @@ public:
NS_DECL_NSIASYNCINPUTSTREAM
NS_DECL_NSISEEKABLESTREAM
NS_DECL_NSISEARCHABLEINPUTSTREAM
NS_DECL_NSICLASSINFO
nsPipeInputStream(nsPipe *pipe)
: mPipe(pipe)
@ -162,6 +165,7 @@ private:
// the output end of a pipe (allocated as a member of the pipe).
class nsPipeOutputStream : public nsIAsyncOutputStream
, public nsISeekableStream
, public nsIClassInfo
{
public:
// since this class will be allocated as a member of the pipe, we do not
@ -174,6 +178,7 @@ public:
NS_DECL_NSIOUTPUTSTREAM
NS_DECL_NSIASYNCOUTPUTSTREAM
NS_DECL_NSISEEKABLESTREAM
NS_DECL_NSICLASSINFO
nsPipeOutputStream(nsPipe *pipe)
: mPipe(pipe)
@ -598,6 +603,21 @@ nsPipeEvents::~nsPipeEvents()
// nsPipeInputStream methods:
//-----------------------------------------------------------------------------
NS_IMPL_QUERY_INTERFACE5(nsPipeInputStream,
nsIInputStream,
nsIAsyncInputStream,
nsISeekableStream,
nsISearchableInputStream,
nsIClassInfo)
NS_IMPL_CI_INTERFACE_GETTER4(nsPipeInputStream,
nsIInputStream,
nsIAsyncInputStream,
nsISeekableStream,
nsISearchableInputStream)
NS_IMPL_THREADSAFE_CI(nsPipeInputStream)
nsresult
nsPipeInputStream::Wait()
{
@ -676,12 +696,6 @@ nsPipeInputStream::Release(void)
return mPipe->Release();
}
NS_IMPL_QUERY_INTERFACE4(nsPipeInputStream,
nsIInputStream,
nsIAsyncInputStream,
nsISeekableStream,
nsISearchableInputStream)
NS_IMETHODIMP
nsPipeInputStream::CloseWithStatus(nsresult reason)
{
@ -952,6 +966,18 @@ nsPipeInputStream::Search(const char *forString,
// nsPipeOutputStream methods:
//-----------------------------------------------------------------------------
NS_IMPL_QUERY_INTERFACE3(nsPipeOutputStream,
nsIOutputStream,
nsIAsyncOutputStream,
nsIClassInfo)
NS_IMPL_CI_INTERFACE_GETTER3(nsPipeOutputStream,
nsIOutputStream,
nsIAsyncOutputStream,
nsISeekableStream)
NS_IMPL_THREADSAFE_CI(nsPipeOutputStream)
nsresult
nsPipeOutputStream::Wait()
{
@ -1027,10 +1053,6 @@ nsPipeOutputStream::Release()
return mPipe->Release();
}
NS_IMPL_QUERY_INTERFACE2(nsPipeOutputStream,
nsIOutputStream,
nsIAsyncOutputStream)
NS_IMETHODIMP
nsPipeOutputStream::CloseWithStatus(nsresult reason)
{

Просмотреть файл

@ -39,10 +39,14 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const CC = Components.Constructor;
var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init");
function run_test()
{
test_not_initialized();
test_ends_are_threadsafe();
}
function test_not_initialized()
@ -60,3 +64,32 @@ function test_not_initialized()
do_throw("using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED");
}
}
function test_ends_are_threadsafe()
{
var p, is, os;
p = new Pipe(true, true, 1024, 1, null);
is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
p = new Pipe(true, false, 1024, 1, null);
is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
p = new Pipe(false, true, 1024, 1, null);
is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
p = new Pipe(false, false, 1024, 1, null);
is = p.inputStream.QueryInterface(Ci.nsIClassInfo);
os = p.outputStream.QueryInterface(Ci.nsIClassInfo);
do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE));
do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE));
}