* Made the private kernel locking primitives available to file systems as well.
* Applied Korli's mutex_unlock() fix to block_cache.cpp. * Removed block_cache_priv.h, as it's no longer needed (moved its definitions into block_cache.cpp, as in the kernel file). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26296 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2008, Ingo Weinhold, [email protected].
|
||||
* Copyright 2002-2008, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
||||
* Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
#ifndef _FSSH_KERNEL_LOCK_H
|
||||
#define _FSSH_KERNEL_LOCK_H
|
||||
|
||||
|
||||
#include <fssh_auto_locker.h>
|
||||
#include <fssh_errors.h>
|
||||
#include <fssh_os.h>
|
||||
|
||||
|
||||
typedef struct fssh_mutex {
|
||||
fssh_sem_id sem;
|
||||
fssh_thread_id holder;
|
||||
} fssh_mutex;
|
||||
|
||||
#define FSSH_MUTEX_FLAG_CLONE_NAME 0x1
|
||||
|
||||
|
||||
typedef struct fssh_recursive_lock {
|
||||
fssh_sem_id sem;
|
||||
fssh_thread_id holder;
|
||||
int recursion;
|
||||
} fssh_recursive_lock;
|
||||
|
||||
|
||||
typedef struct fssh_rw_lock {
|
||||
fssh_sem_id sem;
|
||||
int32_t count;
|
||||
} fssh_rw_lock;
|
||||
|
||||
#define FSSH_RW_LOCK_FLAG_CLONE_NAME 0x1
|
||||
|
||||
#define FSSH_ASSERT_LOCKED_RECURSIVE(r)
|
||||
#define FSSH_ASSERT_LOCKED_MUTEX(m)
|
||||
|
||||
// static initializers
|
||||
#define FSSH_MUTEX_INITIALIZER(name) { name, NULL, 0, 0 }
|
||||
#define FSSH_RECURSIVE_LOCK_INITIALIZER(name) { FSSH_MUTEX_INITIALIZER(name), -1, 0 }
|
||||
#define FSSH_RW_LOCK_INITIALIZER(name) { name, NULL, -1, 0, 0, 0 }
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void fssh_recursive_lock_init(fssh_recursive_lock *lock, const char *name);
|
||||
// name is *not* cloned nor freed in recursive_lock_destroy()
|
||||
extern void fssh_recursive_lock_init_etc(fssh_recursive_lock *lock, const char *name,
|
||||
uint32_t flags);
|
||||
extern void fssh_recursive_lock_destroy(fssh_recursive_lock *lock);
|
||||
extern fssh_status_t fssh_recursive_lock_lock(fssh_recursive_lock *lock);
|
||||
extern void fssh_recursive_lock_unlock(fssh_recursive_lock *lock);
|
||||
extern int32_t fssh_recursive_lock_get_recursion(fssh_recursive_lock *lock);
|
||||
|
||||
extern void fssh_rw_lock_init(fssh_rw_lock* lock, const char* name);
|
||||
// name is *not* cloned nor freed in rw_lock_destroy()
|
||||
extern void fssh_rw_lock_init_etc(fssh_rw_lock* lock, const char* name, uint32_t flags);
|
||||
extern void fssh_rw_lock_destroy(fssh_rw_lock* lock);
|
||||
extern fssh_status_t fssh_rw_lock_read_lock(fssh_rw_lock* lock);
|
||||
extern fssh_status_t fssh_rw_lock_read_unlock(fssh_rw_lock* lock);
|
||||
extern fssh_status_t fssh_rw_lock_write_lock(fssh_rw_lock* lock);
|
||||
extern fssh_status_t fssh_rw_lock_write_unlock(fssh_rw_lock* lock);
|
||||
|
||||
extern void fssh_mutex_init(fssh_mutex* lock, const char* name);
|
||||
// name is *not* cloned nor freed in mutex_destroy()
|
||||
extern void fssh_mutex_init_etc(fssh_mutex* lock, const char* name, uint32_t flags);
|
||||
extern void fssh_mutex_destroy(fssh_mutex* lock);
|
||||
extern fssh_status_t fssh_mutex_lock(fssh_mutex* lock);
|
||||
extern fssh_status_t fssh_mutex_trylock(fssh_mutex* lock);
|
||||
extern void fssh_mutex_unlock(fssh_mutex* lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
namespace FSShell {
|
||||
|
||||
// MutexLocking
|
||||
class MutexLocking {
|
||||
public:
|
||||
inline bool Lock(fssh_mutex *lockable)
|
||||
{
|
||||
return fssh_mutex_lock(lockable) == FSSH_B_OK;
|
||||
}
|
||||
|
||||
inline void Unlock(fssh_mutex *lockable)
|
||||
{
|
||||
fssh_mutex_unlock(lockable);
|
||||
}
|
||||
};
|
||||
|
||||
// MutexLocker
|
||||
typedef AutoLocker<fssh_mutex, MutexLocking> MutexLocker;
|
||||
|
||||
// RecursiveLockLocking
|
||||
class RecursiveLockLocking {
|
||||
public:
|
||||
inline bool Lock(fssh_recursive_lock *lockable)
|
||||
{
|
||||
return fssh_recursive_lock_lock(lockable) == FSSH_B_OK;
|
||||
}
|
||||
|
||||
inline void Unlock(fssh_recursive_lock *lockable)
|
||||
{
|
||||
fssh_recursive_lock_unlock(lockable);
|
||||
}
|
||||
};
|
||||
|
||||
// RecursiveLocker
|
||||
typedef AutoLocker<fssh_recursive_lock, RecursiveLockLocking> RecursiveLocker;
|
||||
|
||||
} // namespace FSShell
|
||||
|
||||
using FSShell::AutoLocker;
|
||||
using FSShell::MutexLocker;
|
||||
using FSShell::RecursiveLocker;
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* _FSSH_KERNEL_LOCK_H */
|
||||
Reference in New Issue
Block a user