1 // 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 8 #include "base/auto_reset.h" 9 #include "base/base_export.h" 10 #include "base/containers/span.h" 11 #include "base/dcheck_is_on.h" 12 13 namespace base::subtle { 14 15 #if DCHECK_IS_ON() 16 // Returns addresses of locks acquired by the current thread with 17 // `subtle::LockTracking::kEnabled`. `uintptr_t` is used because addresses are 18 // meant to be used as unique identifiers but not to be dereferenced. 19 BASE_EXPORT span<const uintptr_t> GetTrackedLocksHeldByCurrentThread(); 20 #endif 21 22 // Whether to add a lock to the list returned by 23 // `subtle::GetLocksHeldByCurrentThread()` upon acquisition. This has no effect 24 // in non-DCHECK builds because tracking is always disabled. This is disabled by 25 // default to avoid exceeding the fixed-size storage backing 26 // `GetTrackedLocksHeldByCurrentThread()` and to avoid reentrancy, e.g.: 27 // 28 // thread_local implementation 29 // Add lock to the thread_local array of locks held by current thread 30 // base::Lock::Acquire from allocator shim 31 // ... Allocator shim ... 32 // thread_local implementation 33 // Access to a thread_local variable 34 // 35 // A lock acquired with `subtle::LockTracking::kEnabled` can be used to provide 36 // a mutual exclusion guarantee for SEQUENCE_CHECKER. 37 enum class LockTracking { 38 kDisabled, 39 kEnabled, 40 }; 41 42 } // namespace base::subtle 43 44 #endif // BASE_SYNCHRONIZATION_LOCK_SUBTLE_H_ 45