/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-native/ReactCommon/react/runtime/BufferedRuntimeExecutor.cpp
58 строк
2 KB
Christoph Purrer
Apply clang-tidy setting: react/renderer|perflogger (#52739)
23 июл 2025, 08:06
23 июл 2025, 08:06
730a0d5
Код
Авторство
О чём код?
/* * 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. */ #include "BufferedRuntimeExecutor.h" namespace facebook::react { BufferedRuntimeExecutor::BufferedRuntimeExecutor( RuntimeExecutor runtimeExecutor) : runtimeExecutor_(std::move(runtimeExecutor)), isBufferingEnabled_(true), lastIndex_(0) {} void BufferedRuntimeExecutor::execute(Work&& callback) { if (!isBufferingEnabled_) { // Fast path: Schedule directly to RuntimeExecutor, without locking runtimeExecutor_(std::move(callback)); return; } /** * Note: std::mutex doesn't have a FIFO ordering. * To preserve the order of the buffered work, use a priority queue and * track the last known work index. */ uint64_t newIndex = lastIndex_++; std::scoped_lock guard(lock_); if (isBufferingEnabled_) { queue_.push({.index_ = newIndex, .work_ = std::move(callback)}); return; } // Force flush the queue to maintain the execution order. unsafeFlush(); runtimeExecutor_(std::move(callback)); } void BufferedRuntimeExecutor::flush() { std::scoped_lock guard(lock_); unsafeFlush(); isBufferingEnabled_ = false; } void BufferedRuntimeExecutor::unsafeFlush() { while (!queue_.empty()) { const BufferedWork& bufferedWork = queue_.top(); Work work = bufferedWork.work_; runtimeExecutor_(std::move(work)); queue_.pop(); } } } // namespace facebook::react