6 class Spin_lock_base : protected Cpu_lock
9 enum Lock_init { Unlocked = 0 };
13 * \brief Basic spin lock.
15 * Also disables lock IRQs for the time the lock is held.
16 * In the UP case it is in fact just the Cpu_lock.
18 template<typename Lock_t = Small_atomic_int>
19 class Spin_lock : public Spin_lock_base
23 //--------------------------------------------------------------------------
26 EXTENSION class Spin_lock
30 explicit Spin_lock(Lock_init) {}
33 using Cpu_lock::Status;
36 using Cpu_lock::clear;
37 using Cpu_lock::test_and_set;
43 * \brief Version of a spin lock that is colocated with another value.
45 template< typename T >
46 class Spin_lock_coloc : public Spin_lock<Mword>
49 enum { Arch_lock = 1 };
54 //--------------------------------------------------------------------------
57 EXTENSION class Spin_lock
62 explicit Spin_lock(Lock_init i) : _lock((i == Unlocked) ? 0 : Arch_lock) {}
69 * \brief Version of a spin lock that is colocated with another value.
71 template< typename T >
72 class Spin_lock_coloc : public Spin_lock<Mword>
76 //--------------------------------------------------------------------------
80 template< typename T >
81 Spin_lock_coloc<T>::Spin_lock_coloc() {}
84 template< typename T >
85 Spin_lock_coloc<T>::Spin_lock_coloc(Lock_init i) : Spin_lock<Mword>(i) {}
88 template< typename T >
90 Spin_lock_coloc<T>::get_unused() const
91 { return (T)(_lock & ~Arch_lock); }
94 template< typename T >
96 Spin_lock_coloc<T>::set_unused(T val)
97 { _lock = (_lock & Arch_lock) | (Mword)val; }
100 //--------------------------------------------------------------------------
106 PUBLIC template<typename Lock_t> inline
108 Spin_lock<Lock_t>::init()
113 PUBLIC template<typename Lock_t> inline
114 typename Spin_lock<Lock_t>::Status
115 Spin_lock<Lock_t>::test() const
117 return (!!cpu_lock.test()) | (_lock & Arch_lock);
120 PUBLIC template<typename Lock_t> inline NEEDS[<cassert>, Spin_lock::lock_arch, "mem.h"]
122 Spin_lock<Lock_t>::lock()
124 assert(!cpu_lock.test());
130 PUBLIC template<typename Lock_t> inline NEEDS[Spin_lock::unlock_arch, "mem.h"]
132 Spin_lock<Lock_t>::clear()
139 PUBLIC template<typename Lock_t> inline NEEDS[Spin_lock::lock_arch, "mem.h"]
140 typename Spin_lock<Lock_t>::Status
141 Spin_lock<Lock_t>::test_and_set()
143 Status s = !!cpu_lock.test();
150 PUBLIC template<typename Lock_t> inline
152 Spin_lock<Lock_t>::set(Status s)
155 if (!(s & Arch_lock))