2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-11-15 05:47:30 +03:00
|
|
|
/* 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 mozilla_dom_workers_WorkerThread_h__
|
|
|
|
#define mozilla_dom_workers_WorkerThread_h__
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-11-17 22:55:37 +03:00
|
|
|
#include "mozilla/CondVar.h"
|
2014-11-15 05:47:30 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-11-15 05:47:30 +03:00
|
|
|
#include "nsThread.h"
|
|
|
|
|
|
|
|
class nsIRunnable;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace workers {
|
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
class RuntimeService;
|
2014-11-15 05:47:30 +03:00
|
|
|
class WorkerPrivate;
|
2014-11-17 22:55:37 +03:00
|
|
|
template <class> class WorkerPrivateParent;
|
2014-11-15 05:47:30 +03:00
|
|
|
class WorkerRunnable;
|
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
// This class lets us restrict the public methods that can be called on
|
|
|
|
// WorkerThread to RuntimeService and WorkerPrivate without letting them gain
|
|
|
|
// full access to private methods (as would happen if they were simply friends).
|
|
|
|
class WorkerThreadFriendKey
|
|
|
|
{
|
|
|
|
friend class RuntimeService;
|
|
|
|
friend class WorkerPrivate;
|
|
|
|
friend class WorkerPrivateParent<WorkerPrivate>;
|
|
|
|
|
|
|
|
WorkerThreadFriendKey();
|
|
|
|
~WorkerThreadFriendKey();
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class WorkerThread final
|
2014-11-15 05:47:30 +03:00
|
|
|
: public nsThread
|
|
|
|
{
|
|
|
|
class Observer;
|
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
CondVar mWorkerPrivateCondVar;
|
|
|
|
|
|
|
|
// Protected by nsThread::mLock.
|
2014-11-15 05:47:30 +03:00
|
|
|
WorkerPrivate* mWorkerPrivate;
|
2014-11-17 22:55:37 +03:00
|
|
|
|
|
|
|
// Only touched on the target thread.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Observer> mObserver;
|
2014-11-15 05:47:30 +03:00
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
// Protected by nsThread::mLock and waited on with mWorkerPrivateCondVar.
|
2015-01-15 00:50:03 +03:00
|
|
|
uint32_t mOtherThreadsDispatchingViaEventTarget;
|
2014-11-17 22:55:37 +03:00
|
|
|
|
2016-02-26 18:52:06 +03:00
|
|
|
#ifdef DEBUG
|
2014-11-15 05:47:30 +03:00
|
|
|
// Protected by nsThread::mLock.
|
2016-02-26 18:52:06 +03:00
|
|
|
bool mAcceptingNonWorkerRunnables;
|
|
|
|
#endif
|
2014-11-15 05:47:30 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<WorkerThread>
|
2014-11-17 22:55:37 +03:00
|
|
|
Create(const WorkerThreadFriendKey& aKey);
|
2014-11-15 05:47:30 +03:00
|
|
|
|
|
|
|
void
|
2014-11-17 22:55:37 +03:00
|
|
|
SetWorker(const WorkerThreadFriendKey& aKey, WorkerPrivate* aWorkerPrivate);
|
2014-11-15 05:47:30 +03:00
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
nsresult
|
|
|
|
DispatchPrimaryRunnable(const WorkerThreadFriendKey& aKey,
|
2015-07-10 06:21:46 +03:00
|
|
|
already_AddRefed<nsIRunnable>&& aRunnable);
|
2014-11-15 05:47:30 +03:00
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
nsresult
|
2015-07-10 06:21:46 +03:00
|
|
|
DispatchAnyThread(const WorkerThreadFriendKey& aKey,
|
|
|
|
already_AddRefed<WorkerRunnable>&& aWorkerRunnable);
|
2014-11-15 05:47:30 +03:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
uint32_t
|
|
|
|
RecursionDepth(const WorkerThreadFriendKey& aKey) const;
|
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-11-15 05:47:30 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
WorkerThread();
|
|
|
|
~WorkerThread();
|
2014-11-17 22:55:37 +03:00
|
|
|
|
|
|
|
// This should only be called by consumers that have an
|
|
|
|
// nsIEventTarget/nsIThread pointer.
|
|
|
|
NS_IMETHOD
|
2015-07-10 06:21:46 +03:00
|
|
|
Dispatch(already_AddRefed<nsIRunnable>&& aRunnable, uint32_t aFlags) override;
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
DispatchFromScript(nsIRunnable* aRunnable, uint32_t aFlags) override;
|
2016-05-13 01:15:43 +03:00
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
DelayedDispatch(already_AddRefed<nsIRunnable>&&, uint32_t) override;
|
2014-11-15 05:47:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace workers
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_WorkerThread_h__
|