зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1431755 - Part 1: Add a variant of NS_GetCurrentThread that does not auto-create an nsIThread. r=froydnj
MozReview-Commit-ID: 9naTxaANX4u --HG-- extra : rebase_source : 8ab21e09a6c154b90bd233212680fa93a96e0106
This commit is contained in:
Родитель
f28ba7ec51
Коммит
c3c54d2281
|
@ -425,6 +425,12 @@ nsThreadManager::GetCurrentThread()
|
|||
return thread.get(); // reference held in TLS
|
||||
}
|
||||
|
||||
bool
|
||||
nsThreadManager::IsNSThread() const
|
||||
{
|
||||
return mInitialized && !!PR_GetThreadPrivate(mCurThreadIndex);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadManager::NewThread(uint32_t aCreationFlags,
|
||||
uint32_t aStackSize,
|
||||
|
|
|
@ -39,9 +39,13 @@ public:
|
|||
void UnregisterCurrentThread(nsThread& aThread);
|
||||
|
||||
// Returns the current thread. Returns null if OOM or if ThreadManager isn't
|
||||
// initialized.
|
||||
// initialized. Creates the nsThread if one does not exist yet.
|
||||
nsThread* GetCurrentThread();
|
||||
|
||||
// Returns true iff the currently running thread has an nsThread associated
|
||||
// with it (ie; whether this is a thread that we can dispatch runnables to).
|
||||
bool IsNSThread() const;
|
||||
|
||||
// CreateCurrentThread sets up an nsThread for the current thread. It uses the
|
||||
// event queue and main thread flags passed in. It should only be called once
|
||||
// for the current thread. After it returns, GetCurrentThread() will return
|
||||
|
|
|
@ -530,6 +530,16 @@ NS_GetCurrentThread()
|
|||
{
|
||||
return nsThreadManager::get().GetCurrentThread();
|
||||
}
|
||||
|
||||
|
||||
nsIThread*
|
||||
NS_GetCurrentThreadNoCreate()
|
||||
{
|
||||
if (nsThreadManager::get().IsNSThread()) {
|
||||
return NS_GetCurrentThread();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
// nsThreadPoolNaming
|
||||
|
|
|
@ -74,7 +74,7 @@ NS_NewNamedThread(const char (&aName)[LEN],
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a reference to the current thread.
|
||||
* Get a reference to the current thread, creating it if it does not exist yet.
|
||||
*
|
||||
* @param aResult
|
||||
* The resulting nsIThread object.
|
||||
|
@ -368,12 +368,19 @@ do_GetMainThread()
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
// Fast access to the current thread. Do not release the returned pointer! If
|
||||
// you want to use this pointer from some other thread, then you will need to
|
||||
// AddRef it. Otherwise, you should only consider this pointer valid from code
|
||||
// running on the current thread.
|
||||
// Fast access to the current thread. Will create an nsIThread if one does not
|
||||
// exist already! Do not release the returned pointer! If you want to use this
|
||||
// pointer from some other thread, then you will need to AddRef it. Otherwise,
|
||||
// you should only consider this pointer valid from code running on the current
|
||||
// thread.
|
||||
extern nsIThread* NS_GetCurrentThread();
|
||||
|
||||
// Exactly the same as NS_GetCurrentThread, except it will not create an
|
||||
// nsThread if one does not exist yet. This is useful in cases where you have
|
||||
// code that runs on threads that may or may not not be driven by an nsThread
|
||||
// event loop, and wish to avoid inadvertently creating a superfluous nsThread.
|
||||
extern nsIThread* NS_GetCurrentThreadNoCreate();
|
||||
|
||||
/**
|
||||
* Set the name of the current thread. Prefer this function over
|
||||
* PR_SetCurrentThreadName() if possible. The name will also be included in the
|
||||
|
|
Загрузка…
Ссылка в новой задаче