зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1207753 - dom/promises thread-safety annotations r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D130947
This commit is contained in:
Родитель
a75b92ee74
Коммит
5f6fb83e59
|
@ -762,6 +762,10 @@ WorkerPrivate* PromiseWorkerProxy::GetWorkerPrivate() const {
|
|||
return mWorkerRef->Private();
|
||||
}
|
||||
|
||||
bool PromiseWorkerProxy::OnWritingThread() const {
|
||||
return IsCurrentThreadRunningWorker();
|
||||
}
|
||||
|
||||
Promise* PromiseWorkerProxy::WorkerPromise() const {
|
||||
MOZ_ASSERT(IsCurrentThreadRunningWorker());
|
||||
MOZ_ASSERT(mWorkerPromise);
|
||||
|
|
|
@ -117,7 +117,8 @@ class WorkerPrivate;
|
|||
// references to it are dropped.
|
||||
|
||||
class PromiseWorkerProxy : public PromiseNativeHandler,
|
||||
public StructuredCloneHolderBase {
|
||||
public StructuredCloneHolderBase,
|
||||
public SingleWriterLockOwner {
|
||||
friend class PromiseWorkerProxyRunnable;
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
@ -132,6 +133,8 @@ class PromiseWorkerProxy : public PromiseNativeHandler,
|
|||
PromiseWorkerProxy* aProxy,
|
||||
JS::HandleObject aObj);
|
||||
|
||||
bool OnWritingThread() const override;
|
||||
|
||||
struct PromiseWorkerProxyStructuredCloneCallbacks {
|
||||
ReadCallbackOp Read;
|
||||
WriteCallbackOp Write;
|
||||
|
@ -144,7 +147,7 @@ class PromiseWorkerProxy : public PromiseNativeHandler,
|
|||
// Main thread callers must hold Lock() and check CleanUp() before calling
|
||||
// this. Worker thread callers, this will assert that the proxy has not been
|
||||
// cleaned up.
|
||||
WorkerPrivate* GetWorkerPrivate() const;
|
||||
WorkerPrivate* GetWorkerPrivate() const NO_THREAD_SAFETY_ANALYSIS;
|
||||
|
||||
// This should only be used within WorkerRunnable::WorkerRun() running on the
|
||||
// worker thread! Do not call this after calling CleanUp().
|
||||
|
@ -156,9 +159,9 @@ class PromiseWorkerProxy : public PromiseNativeHandler,
|
|||
// 2. WorkerPromise() will crash!
|
||||
void CleanUp();
|
||||
|
||||
Mutex& Lock() { return mCleanUpLock; }
|
||||
Mutex& Lock() RETURN_CAPABILITY(mCleanUpLock) { return mCleanUpLock; }
|
||||
|
||||
bool CleanedUp() const {
|
||||
bool CleanedUp() const REQUIRES(mCleanUpLock) {
|
||||
mCleanUpLock.AssertCurrentThreadOwns();
|
||||
return mCleanedUp;
|
||||
}
|
||||
|
@ -202,12 +205,15 @@ class PromiseWorkerProxy : public PromiseNativeHandler,
|
|||
// Modified on the worker thread.
|
||||
// It is ok to *read* this without a lock on the worker.
|
||||
// Main thread must always acquire a lock.
|
||||
bool mCleanedUp; // To specify if the cleanUp() has been done.
|
||||
bool mCleanedUp
|
||||
GUARDED_BY(mCleanUpLock); // To specify if the cleanUp() has been done.
|
||||
|
||||
const PromiseWorkerProxyStructuredCloneCallbacks* mCallbacks;
|
||||
|
||||
// Ensure the worker and the main thread won't race to access |mCleanedUp|.
|
||||
Mutex mCleanUpLock MOZ_UNANNOTATED;
|
||||
// Should be a MutexSingleWriter, but that causes a lot of issues when you
|
||||
// expose the lock via Lock().
|
||||
Mutex mCleanUpLock;
|
||||
};
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
Загрузка…
Ссылка в новой задаче