mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1187817. Part 1 - Move Set{Volume,PlaybackRate,PreservesPitch} to the audio thread. r=kinetik. (a234a7080)
- Bug 1187817. Part 2 - remove unused code. r=kinetik. (836c52a19)
- Bug 1187763. Part 1 - move while loop out of WaitingForAudioToPlay(). r=kinetik. (a80d70f87)
- Bug 1187763. Part 2 - extract some code of AudioLoop() into its own function. r=kinetik. (275b8bfb6)
- Bug 1187763. Part 3 - refactor AudioSink::AudioLoop into a series of events. r=kinetik (7eb3f506f)
- Bug 1187817. Part 3 - move SetPlaying to the audio thread. r=kinetik. (0fef85968)
- Bug 1187817. Part 4 - move some code in Shutdown to the audio thread. r=kinetik. (8c73fbe6d)
- Bug 1187817. Part 5 - assert some code in the audio thread and don't enter the monitor. r=kinetik. (64de4616f)
- move include (f842b4b1e)
- Bug 1163486 - Update test to use new MP4Demuxer. r=bholley (b853be477)
- Bug 1190496 - Namespace the SharedThreadPool.h include. r=cpearce (196d25d42)
- Bug 1190496 - Hoist SharedThreadPool into xpcom. r=froydnj (3dad8176f)
- Bug 1190492 - Hoist AbstractThread and TaskDispatcher to xpcom. r=froydnj (c3329fa29)
- bug 1166107 documentation of mWaitForInternalDrain thread access r=gerald (f762764b1)
- correct comment (b623b2959)
- revert demuxer check from promise reject to assert like in 1156708 (f540b270c)
- more chekcs back to asserts (7e82a0f99)
- space (733bd85a3)
- Bug 1188220: Allow disabling HW acceleration even when SharedDecoderManager isn't used. r=cpearce (909a86682)
- bug 1161903 ensure pending DrainComplete is not run after Flush() r=cpearce (648cabbb7)
- Bug 1158089 - Fall back to d3d9 DXVA if d3d11 initialization fails. r=cpearce (84b3a8e6d)
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef SharedThreadPool_h_
|
||||
#define SharedThreadPool_h_
|
||||
|
||||
#include <queue>
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsIThreadManager.h"
|
||||
#include "nsIThreadPool.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// Wrapper that makes an nsIThreadPool a singleton, and provides a
|
||||
// consistent threadsafe interface to get instances. Callers simply get a
|
||||
// SharedThreadPool by the name of its nsIThreadPool. All get requests of
|
||||
// the same name get the same SharedThreadPool. Users must store a reference
|
||||
// to the pool, and when the last reference to a SharedThreadPool is dropped
|
||||
// the pool is shutdown and deleted. Users aren't required to manually
|
||||
// shutdown the pool, and can release references on any thread. On Windows
|
||||
// all threads in the pool have MSCOM initialized with COINIT_MULTITHREADED.
|
||||
class SharedThreadPool : public nsIThreadPool
|
||||
{
|
||||
public:
|
||||
|
||||
// Gets (possibly creating) the shared thread pool singleton instance with
|
||||
// thread pool named aName.
|
||||
// *Must* be called on the main thread.
|
||||
static already_AddRefed<SharedThreadPool> Get(const nsCString& aName,
|
||||
uint32_t aThreadLimit = 4);
|
||||
|
||||
// We implement custom threadsafe AddRef/Release pair, that destroys the
|
||||
// the shared pool singleton when the refcount drops to 0. The addref/release
|
||||
// are implemented using locking, so it's not recommended that you use them
|
||||
// in a tight loop.
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
||||
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
|
||||
NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
|
||||
|
||||
// Forward behaviour to wrapped thread pool implementation.
|
||||
NS_FORWARD_SAFE_NSITHREADPOOL(mPool);
|
||||
|
||||
// See bug 1155059 - MSVC forces us to not declare Dispatch normally in idl
|
||||
// NS_FORWARD_SAFE_NSIEVENTTARGET(mEventTarget);
|
||||
nsresult Dispatch(nsIRunnable *event, uint32_t flags) { return !mEventTarget ? NS_ERROR_NULL_POINTER : mEventTarget->Dispatch(event, flags); }
|
||||
|
||||
NS_IMETHOD DispatchFromScript(nsIRunnable *event, uint32_t flags) override {
|
||||
return Dispatch(event, flags);
|
||||
}
|
||||
|
||||
NS_IMETHOD Dispatch(already_AddRefed<nsIRunnable>&& event, uint32_t flags) override
|
||||
{ return !mEventTarget ? NS_ERROR_NULL_POINTER : mEventTarget->Dispatch(Move(event), flags); }
|
||||
|
||||
NS_IMETHOD IsOnCurrentThread(bool *_retval) override { return !mEventTarget ? NS_ERROR_NULL_POINTER : mEventTarget->IsOnCurrentThread(_retval); }
|
||||
|
||||
// Creates necessary statics. Called once at startup.
|
||||
static void InitStatics();
|
||||
|
||||
// Spins the event loop until all thread pools are shutdown.
|
||||
// *Must* be called on the main thread.
|
||||
static void SpinUntilEmpty();
|
||||
|
||||
#if defined(MOZ_ASAN)
|
||||
// Use the system default in ASAN builds, because the default is assumed to be
|
||||
// larger than the size we want to use and is hopefully sufficient for ASAN.
|
||||
static const uint32_t kStackSize = nsIThreadManager::DEFAULT_STACK_SIZE;
|
||||
#elif defined(XP_WIN) || defined(XP_MACOSX) || defined(LINUX)
|
||||
static const uint32_t kStackSize = (256 * 1024);
|
||||
#else
|
||||
// All other platforms use their system defaults.
|
||||
static const uint32_t kStackSize = nsIThreadManager::DEFAULT_STACK_SIZE;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
// Returns whether there are no pools in existence at the moment.
|
||||
static bool IsEmpty();
|
||||
|
||||
// Creates a singleton SharedThreadPool wrapper around aPool.
|
||||
// aName is the name of the aPool, and is used to lookup the
|
||||
// SharedThreadPool in the hash table of all created pools.
|
||||
SharedThreadPool(const nsCString& aName,
|
||||
nsIThreadPool* aPool);
|
||||
virtual ~SharedThreadPool();
|
||||
|
||||
nsresult EnsureThreadLimitIsAtLeast(uint32_t aThreadLimit);
|
||||
|
||||
// Name of mPool.
|
||||
const nsCString mName;
|
||||
|
||||
// Thread pool being wrapped.
|
||||
nsCOMPtr<nsIThreadPool> mPool;
|
||||
|
||||
// Refcount. We implement custom ref counting so that the thread pool is
|
||||
// shutdown in a threadsafe manner and singletonness is preserved.
|
||||
nsrefcnt mRefCnt;
|
||||
|
||||
// mPool QI'd to nsIEventTarget. We cache this, so that we can use
|
||||
// NS_FORWARD_SAFE_NSIEVENTTARGET above.
|
||||
nsCOMPtr<nsIEventTarget> mEventTarget;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // SharedThreadPool_h_
|
||||
Reference in New Issue
Block a user