55#ifndef V8_CANCELABLE_TASK_H_
66#define V8_CANCELABLE_TASK_H_
77
8- #include < map >
8+ #include < unordered_map >
99
1010#include " include/v8-platform.h"
1111#include " src/base/atomic-utils.h"
@@ -24,12 +24,14 @@ class Isolate;
2424// from any fore- and background task/thread.
2525class V8_EXPORT_PRIVATE CancelableTaskManager {
2626 public:
27+ using Id = uint64_t ;
28+
2729 CancelableTaskManager ();
2830
2931 // Registers a new cancelable {task}. Returns the unique {id} of the task that
3032 // can be used to try to abort a task by calling {Abort}.
3133 // Must not be called after CancelAndWait.
32- uint32_t Register (Cancelable* task);
34+ Id Register (Cancelable* task);
3335
3436 // Try to abort running a task identified by {id}. The possible outcomes are:
3537 // (1) The task is already finished running or was canceled before and
@@ -39,7 +41,7 @@ class V8_EXPORT_PRIVATE CancelableTaskManager {
3941 // removed.
4042 //
4143 enum TryAbortResult { kTaskRemoved , kTaskRunning , kTaskAborted };
42- TryAbortResult TryAbort (uint32_t id);
44+ TryAbortResult TryAbort (Id id);
4345
4446 // Cancels all remaining registered tasks and waits for tasks that are
4547 // already running. This disallows subsequent Register calls.
@@ -59,13 +61,13 @@ class V8_EXPORT_PRIVATE CancelableTaskManager {
5961 private:
6062 // Only called by {Cancelable} destructor. The task is done with executing,
6163 // but needs to be removed.
62- void RemoveFinishedTask (uint32_t id);
64+ void RemoveFinishedTask (Id id);
6365
6466 // To mitigate the ABA problem, the api refers to tasks through an id.
65- uint32_t task_id_counter_;
67+ Id task_id_counter_;
6668
6769 // A set of cancelable tasks that are currently registered.
68- std::map< uint32_t , Cancelable*> cancelable_tasks_;
70+ std::unordered_map<Id , Cancelable*> cancelable_tasks_;
6971
7072 // Mutex and condition variable enabling concurrent register and removing, as
7173 // well as waiting for background tasks on {CancelAndWait}.
@@ -89,7 +91,7 @@ class V8_EXPORT_PRIVATE Cancelable {
8991 // a platform. This step transfers ownership to the platform, which destroys
9092 // the task after running it. Since the exact time is not known, we cannot
9193 // access the object after handing it to a platform.
92- uint32_t id () { return id_; }
94+ CancelableTaskManager::Id id () { return id_; }
9395
9496 protected:
9597 bool TryRun () { return status_.TrySetValue (kWaiting , kRunning ); }
@@ -120,7 +122,7 @@ class V8_EXPORT_PRIVATE Cancelable {
120122
121123 CancelableTaskManager* parent_;
122124 base::AtomicValue<Status> status_;
123- uint32_t id_;
125+ CancelableTaskManager::Id id_;
124126
125127 // The counter is incremented for failing tries to cancel a task. This can be
126128 // used by the task itself as an indication how often external entities tried
0 commit comments