1 /* 2 * Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef KERNEL_UTIL_AUTO_LOCKER_H 6 #define KERNEL_UTIL_AUTO_LOCKER_H 7 8 9 #include <lock.h> 10 #include <shared/AutoLocker.h> 11 12 13 namespace BPrivate { 14 15 // MutexLocking 16 class MutexLocking { 17 public: 18 inline bool Lock(mutex *lockable) 19 { 20 return mutex_lock(lockable) == B_OK; 21 } 22 23 inline void Unlock(mutex *lockable) 24 { 25 mutex_unlock(lockable); 26 } 27 }; 28 29 // MutexLocker 30 typedef AutoLocker<mutex, MutexLocking> MutexLocker; 31 32 // RecursiveLockLocking 33 class RecursiveLockLocking { 34 public: 35 inline bool Lock(recursive_lock *lockable) 36 { 37 return recursive_lock_lock(lockable) == B_OK; 38 } 39 40 inline void Unlock(recursive_lock *lockable) 41 { 42 recursive_lock_unlock(lockable); 43 } 44 }; 45 46 // RecursiveLocker 47 typedef AutoLocker<recursive_lock, RecursiveLockLocking> RecursiveLocker; 48 49 // BenaphoreLocking 50 class BenaphoreLocking { 51 public: 52 inline bool Lock(benaphore *lockable) 53 { 54 return benaphore_lock(lockable) == B_OK; 55 } 56 57 inline void Unlock(benaphore *lockable) 58 { 59 benaphore_unlock(lockable); 60 } 61 }; 62 63 // BenaphoreLocker 64 typedef AutoLocker<benaphore, BenaphoreLocking> BenaphoreLocker; 65 66 } // namespace BPrivate 67 68 using BPrivate::AutoLocker; 69 using BPrivate::MutexLocker; 70 using BPrivate::RecursiveLocker; 71 using BPrivate::BenaphoreLocker; 72 73 #endif // KERNEL_UTIL_AUTO_LOCKER_H 74