// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_TASK_SEQUENCE_MANAGER_WORK_DEDUPLICATOR_H_ #define BASE_TASK_SEQUENCE_MANAGER_WORK_DEDUPLICATOR_H_ #include <atomic> #include "base/base_export.h" #include "base/task/sequence_manager/associated_thread_id.h" namespace base { namespace sequence_manager { namespace internal { // This class's job is to prevent redundant DoWorks being posted, which are // expensive. The idea is a DoWork will (maybe) run a task before computing the // delay till the next task. If the task run posts another task, we don't want // it to schedule work because the DoWork will post a continuation as needed // with the latest state taken into consideration (fences, enable / disable // queue, task cancellation, etc...) Other threads can also post DoWork at any // time, including while we're computing the delay till the next task. To // account for that, we have split a DoWork up into two sections: // [OnWorkStarted .. WillCheckForMoreWork] and // [WillCheckForMoreWork .. DidCheckForMoreWork] where DidCheckForMoreWork // detects if another thread called OnWorkRequested. // // Nesting is assumed to be dealt with by the ThreadController. // // Most methods are thread-affine except for On(Delayed)WorkRequested which are // is thread-safe. class BASE_EXPORT WorkDeduplicator { … }; } // namespace internal } // namespace sequence_manager } // namespace base #endif // BASE_TASK_SEQUENCE_MANAGER_WORK_DEDUPLICATOR_H_