Files
sousa-gecko/xpcom/threads/StopGapEventTarget.h
T
Emilio Cobos Álvarez 2223a8bee2 Bug 2054311 - Sort headers in xpcom/. r=xpcom-reviewers,nika
Automatically generated with:

    cp dom/.clang-format xpcom/ && mach format xpcom/**.{cpp,h}

Manual changes:

 * nsTDependentSubstring.cpp was relying on include order, prevent that
   from being changed by clang-format.
 * Missing nsAtom.h include from nsGkAtoms.h
 * nsWindowsHelpers.h needed to keep the include order
 * MemoryPressureLevelMac.h needed mozilla/Attributes.h

Differential Revision: https://phabricator.services.mozilla.com/D311687
2026-07-13 18:24:13 +00:00

47 lines
1.5 KiB
C++

/* 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_StopGapEventTarget_h
#define mozilla_StopGapEventTarget_h
#include "mozilla/Mutex.h"
#include "mozilla/Queue.h"
#include "nsCOMPtr.h"
#include "nsISerialEventTarget.h"
#include "nsISupports.h"
#include "nsTArray.h"
namespace mozilla {
// This is an event target that buffers events until a "real" event target is
// connected to it. This is for situations where events must be dispatched, but
// we don't know *where* yet.
// Note: GetCurrentSerialEventTarget and friends will return the *real* event
// target for tasks that are dispatched to this.
class StopGapEventTarget final : public nsISerialEventTarget {
public:
StopGapEventTarget();
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIEVENTTARGET_FULL
// Call this when you know the real event target. Dispatches all queued
// events right away, and passes subsequent events straight through.
nsresult SetRealEventTarget(nsISerialEventTarget* aRealEventTarget);
private:
virtual ~StopGapEventTarget();
typedef struct TaskStruct {
nsCOMPtr<nsIRunnable> event;
nsIEventTarget::DispatchFlags flags;
} TaskStruct;
Mutex mMutex;
nsCOMPtr<nsISerialEventTarget> mRealEventTarget MOZ_GUARDED_BY(mMutex);
nsTArray<TaskStruct> mTasks MOZ_GUARDED_BY(mMutex);
};
} // namespace mozilla
#endif // mozilla_StopGapEventTarget_h