From be8990115c2e3f95c0511d6702e60f5b3fa52f50 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 28 Aug 2007 02:23:11 +0000 Subject: [PATCH] * Base class of InterruptsLocker was accidentially private. * Added class InterruptsSpinLocker, which disables interrupts and acquires a spinlock all in one. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22086 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/util/AutoLock.h | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/headers/private/kernel/util/AutoLock.h b/headers/private/kernel/util/AutoLock.h index fd40971be3..e51cd88509 100644 --- a/headers/private/kernel/util/AutoLock.h +++ b/headers/private/kernel/util/AutoLock.h @@ -83,7 +83,7 @@ public: }; // InterruptsLocker -class InterruptsLocker : AutoLocker { +class InterruptsLocker : public AutoLocker { public: inline InterruptsLocker(bool alreadyLocked = false, bool lockIfNotLocked = true) @@ -114,6 +114,39 @@ public: // SpinLocker typedef AutoLocker SpinLocker; +// InterruptsSpinLocking +class InterruptsSpinLocking { +public: + struct State { + State(spinlock* lock) + : lock(lock) + { + } + + int state; + spinlock* lock; + }; + + inline bool Lock(spinlock* lockable) + { + fState = disable_interrupts(); + acquire_spinlock(lockable); + return true; + } + + inline void Unlock(spinlock* lockable) + { + release_spinlock(lockable); + restore_interrupts(fState); + } + +private: + int fState; +}; + +// InterruptsSpinLocker +typedef AutoLocker InterruptsSpinLocker; + } // namespace BPrivate using BPrivate::AutoLocker; @@ -122,5 +155,6 @@ using BPrivate::RecursiveLocker; using BPrivate::BenaphoreLocker; using BPrivate::InterruptsLocker; using BPrivate::SpinLocker; +using BPrivate::InterruptsSpinLocker; #endif // KERNEL_UTIL_AUTO_LOCKER_H