ramfs: Use rw_lock instead of recursive_lock for r/w locking.
Also use recursive_lock directly instead of the userlandfs shim class.
This commit is contained in:
@@ -2,11 +2,10 @@
|
|||||||
* Copyright 2007, Ingo Weinhold, [email protected].
|
* Copyright 2007, Ingo Weinhold, [email protected].
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOCKING_H
|
#ifndef LOCKING_H
|
||||||
#define LOCKING_H
|
#define LOCKING_H
|
||||||
|
|
||||||
#include "AutoLocker.h"
|
#include <util/AutoLock.h>
|
||||||
|
|
||||||
class Volume;
|
class Volume;
|
||||||
|
|
||||||
|
|||||||
@@ -139,9 +139,6 @@ Volume::Volume(fs_volume* volume)
|
|||||||
fIndexDirectory(NULL),
|
fIndexDirectory(NULL),
|
||||||
fRootDirectory(NULL),
|
fRootDirectory(NULL),
|
||||||
fName(kDefaultVolumeName),
|
fName(kDefaultVolumeName),
|
||||||
fLocker("volume"),
|
|
||||||
fIteratorLocker("iterators"),
|
|
||||||
fQueryLocker("queries"),
|
|
||||||
fNodeListeners(NULL),
|
fNodeListeners(NULL),
|
||||||
fAnyNodeListeners(),
|
fAnyNodeListeners(),
|
||||||
fEntryListeners(NULL),
|
fEntryListeners(NULL),
|
||||||
@@ -152,6 +149,9 @@ Volume::Volume(fs_volume* volume)
|
|||||||
fAccessTime(0),
|
fAccessTime(0),
|
||||||
fMounted(false)
|
fMounted(false)
|
||||||
{
|
{
|
||||||
|
rw_lock_init(&fLocker, "ramfs volume");
|
||||||
|
recursive_lock_init(&fIteratorLocker, "ramfs iterators");
|
||||||
|
recursive_lock_init(&fQueryLocker, "ramfs queries");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -159,6 +159,10 @@ Volume::Volume(fs_volume* volume)
|
|||||||
Volume::~Volume()
|
Volume::~Volume()
|
||||||
{
|
{
|
||||||
Unmount();
|
Unmount();
|
||||||
|
|
||||||
|
recursive_lock_destroy(&fIteratorLocker);
|
||||||
|
recursive_lock_destroy(&fQueryLocker);
|
||||||
|
rw_lock_destroy(&fLocker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -168,14 +172,6 @@ Volume::Mount(uint32 flags)
|
|||||||
{
|
{
|
||||||
Unmount();
|
Unmount();
|
||||||
|
|
||||||
// check the lockers
|
|
||||||
if (fLocker.InitCheck() < 0)
|
|
||||||
return fLocker.InitCheck();
|
|
||||||
if (fIteratorLocker.InitCheck() < 0)
|
|
||||||
return fIteratorLocker.InitCheck();
|
|
||||||
if (fQueryLocker.InitCheck() < 0)
|
|
||||||
return fQueryLocker.InitCheck();
|
|
||||||
|
|
||||||
status_t error = B_OK;
|
status_t error = B_OK;
|
||||||
// create a block allocator
|
// create a block allocator
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
@@ -724,7 +720,7 @@ Volume::FindAttributeIndex(const char *name, uint32 type)
|
|||||||
void
|
void
|
||||||
Volume::AddQuery(Query *query)
|
Volume::AddQuery(Query *query)
|
||||||
{
|
{
|
||||||
AutoLocker<RecursiveLock> _(fQueryLocker);
|
RecursiveLocker _(fQueryLocker);
|
||||||
|
|
||||||
if (query)
|
if (query)
|
||||||
fQueries.Insert(query);
|
fQueries.Insert(query);
|
||||||
@@ -734,7 +730,7 @@ Volume::AddQuery(Query *query)
|
|||||||
void
|
void
|
||||||
Volume::RemoveQuery(Query *query)
|
Volume::RemoveQuery(Query *query)
|
||||||
{
|
{
|
||||||
AutoLocker<RecursiveLock> _(fQueryLocker);
|
RecursiveLocker _(fQueryLocker);
|
||||||
|
|
||||||
if (query)
|
if (query)
|
||||||
fQueries.Remove(query);
|
fQueries.Remove(query);
|
||||||
@@ -746,7 +742,7 @@ Volume::UpdateLiveQueries(Entry *entry, Node* node, const char *attribute,
|
|||||||
int32 type, const uint8 *oldKey, size_t oldLength, const uint8 *newKey,
|
int32 type, const uint8 *oldKey, size_t oldLength, const uint8 *newKey,
|
||||||
size_t newLength)
|
size_t newLength)
|
||||||
{
|
{
|
||||||
AutoLocker<RecursiveLock> _(fQueryLocker);
|
RecursiveLocker _(fQueryLocker);
|
||||||
|
|
||||||
for (Query* query = fQueries.First();
|
for (Query* query = fQueries.First();
|
||||||
query;
|
query;
|
||||||
@@ -826,53 +822,47 @@ Volume::GetAllocationInfo(AllocationInfo &info)
|
|||||||
bool
|
bool
|
||||||
Volume::ReadLock()
|
Volume::ReadLock()
|
||||||
{
|
{
|
||||||
bool alreadyLocked = fLocker.IsLocked();
|
bool ok = rw_lock_read_lock(&fLocker) == B_OK;
|
||||||
if (fLocker.Lock()) {
|
if (ok && fLocker.owner_count > 1)
|
||||||
if (!alreadyLocked)
|
fAccessTime = system_time();
|
||||||
fAccessTime = system_time();
|
return ok;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadUnlock
|
// ReadUnlock
|
||||||
void
|
void
|
||||||
Volume::ReadUnlock()
|
Volume::ReadUnlock()
|
||||||
{
|
{
|
||||||
fLocker.Unlock();
|
rw_lock_read_unlock(&fLocker);
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteLock
|
// WriteLock
|
||||||
bool
|
bool
|
||||||
Volume::WriteLock()
|
Volume::WriteLock()
|
||||||
{
|
{
|
||||||
bool alreadyLocked = fLocker.IsLocked();
|
bool ok = rw_lock_write_lock(&fLocker) == B_OK;
|
||||||
if (fLocker.Lock()) {
|
if (ok && fLocker.owner_count > 1)
|
||||||
if (!alreadyLocked)
|
fAccessTime = system_time();
|
||||||
fAccessTime = system_time();
|
return ok;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteUnlock
|
// WriteUnlock
|
||||||
void
|
void
|
||||||
Volume::WriteUnlock()
|
Volume::WriteUnlock()
|
||||||
{
|
{
|
||||||
fLocker.Unlock();
|
rw_lock_write_unlock(&fLocker);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IteratorLock
|
// IteratorLock
|
||||||
bool
|
bool
|
||||||
Volume::IteratorLock()
|
Volume::IteratorLock()
|
||||||
{
|
{
|
||||||
return fIteratorLocker.Lock();
|
return recursive_lock_lock(&fIteratorLocker) == B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IteratorUnlock
|
// IteratorUnlock
|
||||||
void
|
void
|
||||||
Volume::IteratorUnlock()
|
Volume::IteratorUnlock()
|
||||||
{
|
{
|
||||||
fIteratorLocker.Unlock();
|
recursive_lock_unlock(&fIteratorLocker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
#include <fs_interface.h>
|
#include <fs_interface.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
#include <lock.h>
|
||||||
|
|
||||||
#include <userlandfs/shared/RecursiveLock.h>
|
|
||||||
#include <util/DoublyLinkedList.h>
|
#include <util/DoublyLinkedList.h>
|
||||||
|
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
@@ -186,9 +186,9 @@ private:
|
|||||||
IndexDirectory *fIndexDirectory;
|
IndexDirectory *fIndexDirectory;
|
||||||
Directory *fRootDirectory;
|
Directory *fRootDirectory;
|
||||||
String fName;
|
String fName;
|
||||||
RecursiveLock fLocker;
|
rw_lock fLocker;
|
||||||
RecursiveLock fIteratorLocker;
|
recursive_lock fIteratorLocker;
|
||||||
RecursiveLock fQueryLocker;
|
recursive_lock fQueryLocker;
|
||||||
NodeListenerTree *fNodeListeners;
|
NodeListenerTree *fNodeListeners;
|
||||||
NodeListenerList fAnyNodeListeners;
|
NodeListenerList fAnyNodeListeners;
|
||||||
EntryListenerTree *fEntryListeners;
|
EntryListenerTree *fEntryListeners;
|
||||||
|
|||||||
Reference in New Issue
Block a user