Skip to content

Commit

Permalink
Make TaskQueueEnabledVoterMap deterministic (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
Domiii committed Jul 6, 2023
1 parent c275c6e commit 1a3c82f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class PLATFORM_EXPORT FrameTaskQueueController {

using TaskQueueEnabledVoterMap = WTF::HashMap<
scoped_refptr<MainThreadTaskQueue>,
std::unique_ptr<base::sequence_manager::TaskQueue::QueueEnabledVoter>>;
std::unique_ptr<base::sequence_manager::TaskQueue::QueueEnabledVoter>,
WTF::RecordReplayRefPtrPointerIdHash<MainThreadTaskQueue>>;

// QueueEnabledVoters for the task queues we've created.
TaskQueueEnabledVoterMap task_queue_enabled_voters_;
Expand Down
41 changes: 41 additions & 0 deletions third_party/blink/renderer/platform/wtf/hash_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "third_party/blink/renderer/platform/wtf/hash_table_deleted_value_type.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"

#include "base/record_replay.h"

namespace WTF {

template <size_t size>
Expand Down Expand Up @@ -148,6 +150,31 @@ struct PtrHash {
static const bool safe_to_compare_to_empty_or_deleted = true;
};

template <typename T>
struct RecordReplayPointerIdHash {
static unsigned GetHash(T* key) {
#if defined(COMPILER_MSVC)
#pragma warning(push)
// work around what seems to be a bug in MSVC's conversion warnings
#pragma warning(disable : 4244)
#endif
if (recordreplay::IsRecordingOrReplaying("pointer-ids")) {
int id = recordreplay::PointerId(key);
if (id) {
return IntHash<int>::GetHash(id);
}
}
return IntHash<uintptr_t>::GetHash(reinterpret_cast<uintptr_t>(key));
#if defined(COMPILER_MSVC)
#pragma warning(pop)
#endif
}
static bool Equal(T* a, T* b) { return a == b; }
static bool Equal(std::nullptr_t, T* b) { return !b; }
static bool Equal(T* a, std::nullptr_t) { return !a; }
static const bool safe_to_compare_to_empty_or_deleted = true;
};

template <typename T>
struct RefPtrHash : PtrHash<T> {
using PtrHash<T>::GetHash;
Expand All @@ -162,6 +189,20 @@ struct RefPtrHash : PtrHash<T> {
static bool Equal(const scoped_refptr<T>& a, T* b) { return a == b; }
};

template <typename T>
struct RecordReplayRefPtrPointerIdHash : RecordReplayPointerIdHash<T> {
using RecordReplayPointerIdHash<T>::GetHash;
static unsigned GetHash(const scoped_refptr<T>& key) {
return GetHash(key.get());
}
using RecordReplayPointerIdHash<T>::Equal;
static bool Equal(const scoped_refptr<T>& a, const scoped_refptr<T>& b) {
return a == b;
}
static bool Equal(T* a, const scoped_refptr<T>& b) { return a == b; }
static bool Equal(const scoped_refptr<T>& a, T* b) { return a == b; }
};

template <typename T>
struct UniquePtrHash : PtrHash<T> {
using PtrHash<T>::GetHash;
Expand Down

0 comments on commit 1a3c82f

Please sign in to comment.