Files
react-native/packages/react-native/ReactCommon/react/runtime/BufferedRuntimeExecutor.h
T
Ruslan ShestopalyukandFacebook GitHub Bot 50c9a47f55 Add missing #pragma once's in ReactCommon
Summary:
## Changelog:
[Internal] -

Was writing some unit tests, accidentally included `ImageProps.h` twice (once directly and once transitively) and realized that we have a handful of files without `#pragma once`.

This fixes it for header files inside `ReactCommon`.

Reviewed By: zeyap

Differential Revision: D54258058

fbshipit-source-id: 70f4e9935304803187d1affd72ed44157b1d8fb3
2024-02-27 09:41:24 -08:00

52 lines
1.2 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <ReactCommon/RuntimeExecutor.h>
#include <jsi/jsi.h>
#include <atomic>
#include <queue>
#include "TimerManager.h"
namespace facebook::react {
class BufferedRuntimeExecutor {
public:
using Work = std::function<void(jsi::Runtime& runtime)>;
// A utility structure to track pending work in the order of when they arrive.
struct BufferedWork {
uint64_t index_;
Work work_;
bool operator<(const BufferedWork& rhs) const {
// Higher index has lower priority, so this inverted comparison puts
// the smaller index on top of the queue.
return index_ > rhs.index_;
}
};
BufferedRuntimeExecutor(RuntimeExecutor runtimeExecutor);
void execute(Work&& callback);
// Flush buffered JS calls and then diable JS buffering
void flush();
private:
// Perform flushing without locking mechanism
void unsafeFlush();
RuntimeExecutor runtimeExecutor_;
bool isBufferingEnabled_;
std::mutex lock_;
std::atomic<uint64_t> lastIndex_;
std::priority_queue<BufferedWork> queue_;
};
} // namespace facebook::react