1 // Copyright 2018 The Fuchsia Authors 2 // 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file or at 5 // https://opensource.org/licenses/MIT 6 7 #pragma once 8 9 #include <lockdep/guard.h> 10 #include <lockdep/guard_multiple.h> 11 #include <lockdep/lockdep.h> 12 13 // Bring some lockdep types into global namespace for the kernel. 14 // TODO(eieio): Is there a better namespace to put these in, or perhaps they 15 // should just be used from the lockdep namespace? 16 using lockdep::AdoptLock; 17 using lockdep::Guard; 18 using lockdep::GuardMultiple; 19 using lockdep::Lock; 20 using lockdep::LockFlagsActiveListDisabled; 21 using lockdep::LockFlagsReportingDisabled; 22 using lockdep::LockFlagsTrackingDisabled; 23 24 // Defines a singleton lock with the given name that wraps a raw global lock. 25 // The singleton instance may be retrieved using the static Get() method 26 // provided by the base class. The raw global lock is used as the underlying 27 // lock instead of an internally-defined lock. This is useful to instrument an 28 // existing global lock that may be shared with C code or for other reasons 29 // cannot be completely replaced with the above global lock type. 30 // 31 // Arguments: 32 // name: The name of the singleton to define. 33 // global_lock: The global lock to wrap with this lock type. This must be an 34 // lvalue reference expression to a lock with static storage 35 // duration, either external or internal. 36 // __VA_ARGS__: LockFlags expression specifying lock flags to honor in addition 37 // to the flags specified for the lock type using the 38 // LOCK_DEP_TRAITS macro below. 39 // 40 // Example usage: 41 // 42 // extern spin_lock_t thread_lock; 43 // LOCK_DEP_SINGLETON_LOCK_WRAPPER(ThreadLock, thread_lock [, LockFlags]); 44 // 45 // void DoThreadStuff() { 46 // Guard<spin_lock_t, IrqSave> guard{ThreadLock::Get()}; 47 // // ... 48 // } 49 #define DECLARE_SINGLETON_LOCK_WRAPPER(name, global_lock, ...) \ 50 LOCK_DEP_SINGLETON_LOCK_WRAPPER(name, global_lock, ##__VA_ARGS__) 51