forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the functionality to merge and unmerge MessageLoopTaskQueues (flu…
…tter#9436) - 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.
- Loading branch information
1 parent
8abe85b
commit 379028a
Showing
12 changed files
with
522 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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. | ||
|
||
#define FML_USED_ON_EMBEDDER | ||
|
||
#include "flutter/fml/message_loop_task_queues.h" | ||
|
||
namespace fml { | ||
|
||
// RAII class for managing merged locks. | ||
class MessageLoopTaskQueues::MergedQueuesRunner { | ||
public: | ||
// TODO (kaushikiska): refactor mutexes out side of MessageLoopTaskQueues | ||
// for better DI. | ||
MergedQueuesRunner(MessageLoopTaskQueues& task_queues, | ||
TaskQueueId owner, | ||
MutexType type = MutexType::kTasks) | ||
: owner_(owner), | ||
subsumed_(task_queues_._kUnmerged), | ||
task_queues_(task_queues), | ||
type_(type) { | ||
task_queues_.GetMutex(owner, type).lock(); | ||
subsumed_ = task_queues_.owner_to_subsumed_[owner]; | ||
if (isMerged(subsumed_)) { | ||
task_queues_.GetMutex(subsumed_, type).lock(); | ||
} | ||
} | ||
|
||
// First invokes on owner and then subsumed (if present). | ||
void InvokeMerged(std::function<void(const TaskQueueId)> closure) { | ||
closure(owner_); | ||
if (isMerged(subsumed_)) { | ||
closure(subsumed_); | ||
} | ||
} | ||
|
||
~MergedQueuesRunner() { | ||
if (isMerged(subsumed_)) { | ||
task_queues_.GetMutex(subsumed_, type_).unlock(); | ||
} | ||
task_queues_.GetMutex(owner_, type_).unlock(); | ||
} | ||
|
||
private: | ||
bool isMerged(TaskQueueId queue_id) { | ||
return queue_id != MessageLoopTaskQueues::_kUnmerged; | ||
} | ||
|
||
const TaskQueueId owner_; | ||
TaskQueueId subsumed_; | ||
MessageLoopTaskQueues& task_queues_; | ||
const MutexType type_; | ||
|
||
FML_DISALLOW_COPY_ASSIGN_AND_MOVE(MergedQueuesRunner); | ||
}; | ||
|
||
} // namespace fml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.