зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1743020 - Part 4: Use MoveOnlyFunction in DataPipe, r=ipc-reviewers,mccr8
This is mostly a simple use-case for the type which I was aware of and could use to ensure it builds correctly. Differential Revision: https://phabricator.services.mozilla.com/D145692
This commit is contained in:
Родитель
85884b7fca
Коммит
a035fb975b
|
@ -10,6 +10,7 @@
|
|||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/ErrorNames.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/MoveOnlyFunction.h"
|
||||
#include "mozilla/ipc/InputStreamParams.h"
|
||||
#include "nsIAsyncInputStream.h"
|
||||
#include "nsStreamUtils.h"
|
||||
|
@ -35,33 +36,19 @@ class SCOPED_CAPABILITY DataPipeAutoLock {
|
|||
|
||||
template <typename F>
|
||||
void AddUnlockAction(F aAction) {
|
||||
mActions.AppendElement(MakeUnique<Action<F>>(std::move(aAction)));
|
||||
mActions.AppendElement(std::move(aAction));
|
||||
}
|
||||
|
||||
~DataPipeAutoLock() CAPABILITY_RELEASE() {
|
||||
mMutex.Unlock();
|
||||
for (auto& action : mActions) {
|
||||
action->Run();
|
||||
action();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// NOTE: This would be better served by something like llvm's
|
||||
// `UniqueFunction`, but this works as well. We can't use `std::function`, as
|
||||
// the actions may not be copy constructable.
|
||||
struct IAction {
|
||||
virtual void Run() = 0;
|
||||
virtual ~IAction() = default;
|
||||
};
|
||||
template <typename F>
|
||||
struct Action : IAction {
|
||||
explicit Action(F&& aAction) : mAction(std::move(aAction)) {}
|
||||
void Run() override { mAction(); }
|
||||
F mAction;
|
||||
};
|
||||
|
||||
Mutex& mMutex;
|
||||
AutoTArray<UniquePtr<IAction>, 4> mActions;
|
||||
AutoTArray<MoveOnlyFunction<void()>, 4> mActions;
|
||||
};
|
||||
|
||||
static void DoNotifyOnUnlock(DataPipeAutoLock& aLock,
|
||||
|
|
Загрузка…
Ссылка в новой задаче