blob: b8fd2aff6154eae3a83b2678b939b95bedc075c9 [file] [log] [blame]
François Dorayefe18b92024-05-31 21:44:591// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_SYNCHRONIZATION_LOCK_SUBTLE_H_
6#define BASE_SYNCHRONIZATION_LOCK_SUBTLE_H_
7
François Dorayefe18b92024-05-31 21:44:598#include "base/base_export.h"
9#include "base/containers/span.h"
10#include "base/dcheck_is_on.h"
11
12namespace base::subtle {
13
14#if DCHECK_IS_ON()
François Doray6671c402024-06-21 17:47:3915// Returns addresses of locks acquired by the current thread with
16// `subtle::LockTracking::kEnabled`. `uintptr_t` is used because addresses are
17// meant to be used as unique identifiers but not to be dereferenced.
18BASE_EXPORT span<const uintptr_t> GetTrackedLocksHeldByCurrentThread();
François Dorayefe18b92024-05-31 21:44:5919#endif
20
François Doray6671c402024-06-21 17:47:3921// Whether to add a lock to the list returned by
22// `subtle::GetLocksHeldByCurrentThread()` upon acquisition. This has no effect
23// in non-DCHECK builds because tracking is always disabled. This is disabled by
24// default to avoid exceeding the fixed-size storage backing
25// `GetTrackedLocksHeldByCurrentThread()` and to avoid reentrancy, e.g.:
26//
27// thread_local implementation
28// Add lock to the thread_local array of locks held by current thread
29// base::Lock::Acquire from allocator shim
30// ... Allocator shim ...
31// thread_local implementation
32// Access to a thread_local variable
33//
34// A lock acquired with `subtle::LockTracking::kEnabled` can be used to provide
35// a mutual exclusion guarantee for SEQUENCE_CHECKER.
36enum class LockTracking {
37 kDisabled,
38 kEnabled,
François Dorayefe18b92024-05-31 21:44:5939};
40
41} // namespace base::subtle
42
43#endif // BASE_SYNCHRONIZATION_LOCK_SUBTLE_H_