Files
flipper/xplat/Flipper/FlipperFollyScopedThreadScheduler.h
Marcelo Lopez Ruiz b7c38556ce Name the Flipper scheduler/threads
Summary:
Plumbs through an optional name for FollyScopedThreadScheduler.
This allows the threads to be named in XCode/lldb.

Differential Revision: D38582449

fbshipit-source-id: 1de50d25c0f91e7003cf81cb22faf4b10a8e23a8
2022-08-10 21:21:39 -07:00

45 lines
1.1 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 "FlipperScheduler.h"
#include <folly/futures/Future.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/ScopedEventBaseThread.h>
namespace facebook {
namespace flipper {
struct FollyScopedThreadScheduler : public Scheduler {
FollyScopedThreadScheduler() : FollyScopedThreadScheduler("") {}
FollyScopedThreadScheduler(folly::StringPiece name)
: thread_(nullptr, name) {}
virtual void schedule(Func&& t) override {
thread_.getEventBase()->add(t);
}
virtual void scheduleAfter(Func&& t, unsigned int ms) override {
folly::makeFuture()
.via(thread_.getEventBase())
.delayed(std::chrono::milliseconds(ms))
.thenValue([t](auto&&) { t(); });
}
virtual bool isRunningInOwnThread() override {
return thread_.getEventBase()->isInEventBaseThread();
}
private:
folly::ScopedEventBaseThread thread_;
};
} // namespace flipper
} // namespace facebook