* Added ReadLocker/WriteLocker classes to auto lock an rw_lock.

* Added *_init_etc() functions to the fs_shell.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26302 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-07-07 18:12:33 +00:00
parent e2dfe00484
commit 06d5e1b3b6
3 changed files with 78 additions and 0 deletions

View File

@ -115,11 +115,42 @@ public:
// RecursiveLocker
typedef AutoLocker<fssh_recursive_lock, RecursiveLockLocking> RecursiveLocker;
class ReadWriteLockReadLocking {
public:
inline bool Lock(fssh_rw_lock *lockable)
{
return fssh_rw_lock_read_lock(lockable) == FSSH_B_OK;
}
inline void Unlock(fssh_rw_lock *lockable)
{
fssh_rw_lock_read_unlock(lockable);
}
};
class ReadWriteLockWriteLocking {
public:
inline bool Lock(fssh_rw_lock *lockable)
{
return fssh_rw_lock_write_lock(lockable) == FSSH_B_OK;
}
inline void Unlock(fssh_rw_lock *lockable)
{
fssh_rw_lock_write_unlock(lockable);
}
};
typedef AutoLocker<fssh_rw_lock, ReadWriteLockReadLocking> ReadLocker;
typedef AutoLocker<fssh_rw_lock, ReadWriteLockWriteLocking> WriteLocker;
} // namespace FSShell
using FSShell::AutoLocker;
using FSShell::MutexLocker;
using FSShell::RecursiveLocker;
using FSShell::ReadLocker;
using FSShell::WriteLocker;
#endif // __cplusplus

View File

@ -1,5 +1,7 @@
/*
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
* 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
@ -50,6 +52,35 @@ public:
// RecursiveLocker
typedef AutoLocker<recursive_lock, RecursiveLockLocking> RecursiveLocker;
class ReadWriteLockReadLocking {
public:
inline bool Lock(rw_lock *lockable)
{
return rw_lock_read_lock(lockable) == B_OK;
}
inline void Unlock(rw_lock *lockable)
{
rw_lock_read_unlock(lockable);
}
};
class ReadWriteLockWriteLocking {
public:
inline bool Lock(rw_lock *lockable)
{
return rw_lock_write_lock(lockable) == B_OK;
}
inline void Unlock(rw_lock *lockable)
{
rw_lock_write_unlock(lockable);
}
};
typedef AutoLocker<rw_lock, ReadWriteLockReadLocking> ReadLocker;
typedef AutoLocker<rw_lock, ReadWriteLockWriteLocking> WriteLocker;
// InterruptsLocking
class InterruptsLocking {
public:
@ -135,6 +166,8 @@ typedef AutoLocker<spinlock, InterruptsSpinLocking> InterruptsSpinLocker;
using BPrivate::AutoLocker;
using BPrivate::MutexLocker;
using BPrivate::RecursiveLocker;
using BPrivate::ReadLocker;
using BPrivate::WriteLocker;
using BPrivate::InterruptsLocker;
using BPrivate::SpinLocker;
using BPrivate::InterruptsSpinLocker;

View File

@ -122,6 +122,13 @@ fssh_mutex_init(fssh_mutex *m, const char *name)
}
extern "C" void
fssh_mutex_init_etc(fssh_mutex *m, const char *name, uint32_t flags)
{
fssh_mutex_init(m, name);
}
extern "C" void
fssh_mutex_destroy(fssh_mutex *mutex)
{
@ -187,6 +194,13 @@ fssh_rw_lock_init(fssh_rw_lock *lock, const char *name)
}
extern "C" void
fssh_rw_lock_init_etc(fssh_rw_lock *lock, const char *name, uint32_t flags)
{
fssh_rw_lock_init(lock, name);
}
extern "C" void
fssh_rw_lock_destroy(fssh_rw_lock *lock)
{