mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Run scheduled executor callback on executor thread
PiperOrigin-RevId: 738998896
This commit is contained in:
committed by
Copybara-Service
parent
12675ff9fa
commit
9e23624fba
@@ -89,6 +89,10 @@ constexpr auto kEnableBlockingSocket =
|
||||
constexpr auto kSocketSendBufferSize =
|
||||
flags::Flag<int64_t>(kConfigPackage, "45673785", 524288);
|
||||
|
||||
// Run scheduled executor callback on executor thread.
|
||||
constexpr auto kRunScheduledExecutorCallbackOnExecutorThread =
|
||||
flags::Flag<bool>(kConfigPackage, "45686494", false);
|
||||
|
||||
} // namespace nearby_platform_feature
|
||||
} // namespace config_package_nearby
|
||||
} // namespace platform
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <utility>
|
||||
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/implementation/cancelable.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/runnable.h"
|
||||
@@ -38,12 +40,22 @@ ScheduledExecutor::ScheduledExecutor()
|
||||
std::shared_ptr<api::Cancelable> ScheduledExecutor::Schedule(
|
||||
Runnable&& runnable, absl::Duration duration) {
|
||||
if (shut_down_) {
|
||||
LOG(ERROR) << __func__
|
||||
<< ": Attempt to Schedule on a shut down executor.";
|
||||
LOG(ERROR) << __func__ << ": Attempt to Schedule on a shut down executor.";
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
return task_scheduler_.Schedule(std::move(runnable), duration);
|
||||
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kRunScheduledExecutorCallbackOnExecutorThread)) {
|
||||
return task_scheduler_.Schedule(
|
||||
[this, runnable = std::move(runnable)]() mutable {
|
||||
Execute(std::move(runnable));
|
||||
},
|
||||
duration);
|
||||
} else {
|
||||
return task_scheduler_.Schedule(std::move(runnable), duration);
|
||||
}
|
||||
}
|
||||
|
||||
void ScheduledExecutor::Execute(Runnable&& runnable) {
|
||||
|
||||
Reference in New Issue
Block a user