forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Delayed Tasks to their own file (flutter#9290)
* Refactor Delayed Tasks to their own class * fix some comments * Update BUILD.gn
- Loading branch information
1 parent
9baf589
commit 87c26ae
Showing
6 changed files
with
85 additions
and
37 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,35 @@ | ||
// 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/delayed_task.h" | ||
|
||
namespace fml { | ||
|
||
DelayedTask::DelayedTask(size_t order, | ||
fml::closure task, | ||
fml::TimePoint target_time) | ||
: order_(order), task_(std::move(task)), target_time_(target_time) {} | ||
|
||
DelayedTask::DelayedTask(const DelayedTask& other) = default; | ||
|
||
DelayedTask::~DelayedTask() = default; | ||
|
||
const fml::closure& DelayedTask::GetTask() const { | ||
return task_; | ||
} | ||
|
||
fml::TimePoint DelayedTask::GetTargetTime() const { | ||
return target_time_; | ||
} | ||
|
||
bool DelayedTask::operator>(const DelayedTask& other) const { | ||
if (target_time_ == other.target_time_) { | ||
return order_ > other.order_; | ||
} | ||
return target_time_ > other.target_time_; | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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. | ||
|
||
#ifndef FLUTTER_FML_DELAYED_TASK_H_ | ||
#define FLUTTER_FML_DELAYED_TASK_H_ | ||
|
||
#include "flutter/fml/closure.h" | ||
#include "flutter/fml/time/time_point.h" | ||
|
||
#include <queue> | ||
|
||
namespace fml { | ||
|
||
class DelayedTask { | ||
public: | ||
DelayedTask(size_t order, fml::closure task, fml::TimePoint target_time); | ||
|
||
DelayedTask(const DelayedTask& other); | ||
|
||
~DelayedTask(); | ||
|
||
const fml::closure& GetTask() const; | ||
|
||
fml::TimePoint GetTargetTime() const; | ||
|
||
bool operator>(const DelayedTask& other) const; | ||
|
||
private: | ||
size_t order_; | ||
fml::closure task_; | ||
fml::TimePoint target_time_; | ||
}; | ||
|
||
using DelayedTaskQueue = std::priority_queue<DelayedTask, | ||
std::deque<DelayedTask>, | ||
std::greater<DelayedTask>>; | ||
|
||
} // namespace fml | ||
|
||
#endif // FLUTTER_FML_DELAYED_TASK_H_ |
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