2007-02-07 17:07:31 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
|
2005-01-30 19:09:06 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef KERNEL_UTIL_AUTO_LOCKER_H
|
|
|
|
#define KERNEL_UTIL_AUTO_LOCKER_H
|
|
|
|
|
2007-02-07 17:07:31 +03:00
|
|
|
|
2005-01-30 19:09:06 +03:00
|
|
|
#include <lock.h>
|
2007-03-27 16:05:33 +04:00
|
|
|
#include <shared/AutoLocker.h>
|
2005-01-30 19:09:06 +03:00
|
|
|
|
2007-02-07 17:07:31 +03:00
|
|
|
|
2005-01-30 19:09:06 +03:00
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
// MutexLocking
|
|
|
|
class MutexLocking {
|
|
|
|
public:
|
|
|
|
inline bool Lock(mutex *lockable)
|
|
|
|
{
|
2007-02-07 17:07:31 +03:00
|
|
|
return mutex_lock(lockable) == B_OK;
|
2005-01-30 19:09:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Unlock(mutex *lockable)
|
|
|
|
{
|
|
|
|
mutex_unlock(lockable);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// MutexLocker
|
|
|
|
typedef AutoLocker<mutex, MutexLocking> MutexLocker;
|
|
|
|
|
|
|
|
// RecursiveLockLocking
|
|
|
|
class RecursiveLockLocking {
|
|
|
|
public:
|
|
|
|
inline bool Lock(recursive_lock *lockable)
|
|
|
|
{
|
2007-02-07 17:07:31 +03:00
|
|
|
return recursive_lock_lock(lockable) == B_OK;
|
2005-01-30 19:09:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Unlock(recursive_lock *lockable)
|
|
|
|
{
|
|
|
|
recursive_lock_unlock(lockable);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// RecursiveLocker
|
|
|
|
typedef AutoLocker<recursive_lock, RecursiveLockLocking> RecursiveLocker;
|
|
|
|
|
2005-04-14 02:40:48 +04:00
|
|
|
// 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;
|
|
|
|
|
2005-01-30 19:09:06 +03:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
using BPrivate::AutoLocker;
|
|
|
|
using BPrivate::MutexLocker;
|
|
|
|
using BPrivate::RecursiveLocker;
|
2005-04-14 02:40:48 +04:00
|
|
|
using BPrivate::BenaphoreLocker;
|
2005-01-30 19:09:06 +03:00
|
|
|
|
|
|
|
#endif // KERNEL_UTIL_AUTO_LOCKER_H
|