2014-11-15 05:47:30 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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"
|
|
|
|
#include "nsRefPtr.h"
|
|
|
|
#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.
|
2014-11-15 05:47:30 +03:00
|
|
|
nsRefPtr<Observer> mObserver;
|
|
|
|
|
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
|
|
|
|
2014-11-15 05:47:30 +03:00
|
|
|
// Protected by nsThread::mLock.
|
2014-11-17 22:55:37 +03:00
|
|
|
DebugOnly<bool> mAcceptingNonWorkerRunnables;
|
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,
|
|
|
|
nsIRunnable* aRunnable);
|
2014-11-15 05:47:30 +03:00
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
nsresult
|
|
|
|
Dispatch(const WorkerThreadFriendKey& aKey,
|
|
|
|
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-03-21 19:28:04 +03:00
|
|
|
Dispatch(nsIRunnable* aRunnable, uint32_t aFlags) override;
|
2014-11-15 05:47:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace workers
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_WorkerThread_h__
|