mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
- Add the functionality to merge and unmerge MessageLoopTaskQueues This introduces a notion of a "owning" and "subsumed" queue ids. Owning queue will take care of the tasks submitted to both that and it's subsumed queue. - The tasks submitted still maintain the queue affinity - Same for the task observers - Also adds MergedQueuesRunner which grabs both the locks owner and subsumed queues in RAII fashion. - Also use task queue id to verify if we are running in the same thread. - This is to enable merging the backed message loop task queues to enable dynamic thread merging in IOS.
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <cassert>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
#include "flutter/benchmarking/benchmarking.h"
|
|
#include "flutter/fml/message_loop_task_queues.h"
|
|
#include "flutter/fml/synchronization/count_down_latch.h"
|
|
|
|
namespace fml {
|
|
namespace benchmarking {
|
|
|
|
static void BM_RegisterAndGetTasks(benchmark::State& state) {
|
|
while (state.KeepRunning()) {
|
|
auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
|
|
|
|
const int num_task_queues = 10;
|
|
const int num_tasks_per_queue = 100;
|
|
const fml::TimePoint past = fml::TimePoint::Now();
|
|
|
|
for (int i = 0; i < num_task_queues; i++) {
|
|
task_queue->CreateTaskQueue();
|
|
}
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
CountDownLatch tasks_registered(num_task_queues);
|
|
CountDownLatch tasks_done(num_task_queues);
|
|
|
|
for (int i = 0; i < num_task_queues; i++) {
|
|
threads.emplace_back([task_runner_id = i, &task_queue, past, &tasks_done,
|
|
&tasks_registered]() {
|
|
for (int j = 0; j < num_tasks_per_queue; j++) {
|
|
task_queue->RegisterTask(
|
|
TaskQueueId(task_runner_id), [] {}, past);
|
|
}
|
|
tasks_registered.CountDown();
|
|
tasks_registered.Wait();
|
|
std::vector<fml::closure> invocations;
|
|
task_queue->GetTasksToRunNow(TaskQueueId(task_runner_id),
|
|
fml::FlushType::kAll, invocations);
|
|
assert(invocations.size() == num_tasks_per_queue);
|
|
tasks_done.CountDown();
|
|
});
|
|
}
|
|
|
|
tasks_done.Wait();
|
|
|
|
for (auto& thread : threads) {
|
|
thread.join();
|
|
}
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_RegisterAndGetTasks);
|
|
|
|
} // namespace benchmarking
|
|
} // namespace fml
|