haiku/headers/private/kernel/util/AutoLock.h
Ingo Weinhold 2b2ec4382a * Moved the AutoLocker class out of the kernel/utils/AutoLock.h header
into its own shared/AutoLocker.h. It can be used by userland code too.
* Removed headers/private/shared/ObjectLocker.h and replaced all uses of
  BObjectLocker by AutoLocker.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20432 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-03-27 12:05:33 +00:00

74 lines
1.4 KiB
C++

/*
* Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef KERNEL_UTIL_AUTO_LOCKER_H
#define KERNEL_UTIL_AUTO_LOCKER_H
#include <lock.h>
#include <shared/AutoLocker.h>
namespace BPrivate {
// MutexLocking
class MutexLocking {
public:
inline bool Lock(mutex *lockable)
{
return mutex_lock(lockable) == B_OK;
}
inline void Unlock(mutex *lockable)
{
mutex_unlock(lockable);
}
};
// MutexLocker
typedef AutoLocker<mutex, MutexLocking> MutexLocker;
// RecursiveLockLocking
class RecursiveLockLocking {
public:
inline bool Lock(recursive_lock *lockable)
{
return recursive_lock_lock(lockable) == B_OK;
}
inline void Unlock(recursive_lock *lockable)
{
recursive_lock_unlock(lockable);
}
};
// RecursiveLocker
typedef AutoLocker<recursive_lock, RecursiveLockLocking> RecursiveLocker;
// BenaphoreLocking
class BenaphoreLocking {
public:
inline bool Lock(benaphore *lockable)
{
return benaphore_lock(lockable) == B_OK;
}
inline void Unlock(benaphore *lockable)
{
benaphore_unlock(lockable);
}
};
// BenaphoreLocker
typedef AutoLocker<benaphore, BenaphoreLocking> BenaphoreLocker;
} // namespace BPrivate
using BPrivate::AutoLocker;
using BPrivate::MutexLocker;
using BPrivate::RecursiveLocker;
using BPrivate::BenaphoreLocker;
#endif // KERNEL_UTIL_AUTO_LOCKER_H