* Replaced Chain with the new SinglyLinkedList.

* Renamed openModeToAccess() to open_mode_to_access().
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26718 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-08-01 14:20:16 +00:00
parent c1c81d42d1
commit 2accd07be4
13 changed files with 298 additions and 356 deletions
@@ -67,7 +67,7 @@ Attribute::CheckAccess(const char *name, int openMode)
|| !strcmp(name, "size")*/)
RETURN_ERROR(B_NOT_ALLOWED);
return fInode->CheckPermissions(openModeToAccess(openMode)
return fInode->CheckPermissions(open_mode_to_access(openMode)
| (openMode & O_TRUNC ? W_OK : 0));
}
@@ -377,9 +377,10 @@ BPlusTree::~BPlusTree()
// traversing the tree - a TreeIterator doesn't lock the inode)
mutex_lock(&fIteratorLock);
TreeIterator *iterator = NULL;
while ((iterator = fIterators.Next(iterator)) != NULL)
iterator->Stop();
SinglyLinkedList<TreeIterator>::Iterator iterator
= fIterators.GetIterator();
while (iterator.HasNext())
iterator.Next()->Stop();
mutex_destroy(&fIteratorLock);
}
@@ -569,9 +570,10 @@ BPlusTree::_UpdateIterators(off_t offset, off_t nextOffset, uint16 keyIndex,
// any time, so we need to protect this loop
MutexLocker _(fIteratorLock);
TreeIterator *iterator = NULL;
while ((iterator = fIterators.Next(iterator)) != NULL)
iterator->Update(offset, nextOffset, keyIndex, splitAt, change);
SinglyLinkedList<TreeIterator>::Iterator iterator
= fIterators.GetIterator();
while (iterator.HasNext())
iterator.Next()->Update(offset, nextOffset, keyIndex, splitAt, change);
}
@@ -1862,8 +1864,7 @@ BPlusTree::Find(const uint8 *key, uint16 keyLength, off_t *_value)
TreeIterator::TreeIterator(BPlusTree *tree)
:
fTree(tree),
fCurrentNodeOffset(BPLUSTREE_NULL),
fNext(NULL)
fCurrentNodeOffset(BPLUSTREE_NULL)
{
tree->_AddIterator(this);
}
+33 -29
View File
@@ -8,7 +8,6 @@
#include "bfs.h"
#include "Journal.h"
#include "Chain.h"
// #pragma mark - on-disk structures
@@ -212,12 +211,18 @@ class BPlusTree {
off_t value);
status_t Insert(Transaction& transaction, const char* key,
off_t value);
status_t Insert(Transaction &transaction, int32 key, off_t value);
status_t Insert(Transaction &transaction, uint32 key, off_t value);
status_t Insert(Transaction &transaction, int64 key, off_t value);
status_t Insert(Transaction &transaction, uint64 key, off_t value);
status_t Insert(Transaction &transaction, float key, off_t value);
status_t Insert(Transaction &transaction, double key, off_t value);
status_t Insert(Transaction& transaction, int32 key,
off_t value);
status_t Insert(Transaction& transaction, uint32 key,
off_t value);
status_t Insert(Transaction& transaction, int64 key,
off_t value);
status_t Insert(Transaction& transaction, uint64 key,
off_t value);
status_t Insert(Transaction& transaction, float key,
off_t value);
status_t Insert(Transaction& transaction, double key,
off_t value);
status_t Replace(Transaction& transaction, const uint8* key,
uint16 keyLength, off_t value);
@@ -227,8 +232,8 @@ class BPlusTree {
static int32 ModeToKeyType(mode_t mode);
private:
BPlusTree(const BPlusTree &);
BPlusTree &operator=(const BPlusTree &);
BPlusTree(const BPlusTree& other);
BPlusTree& operator=(const BPlusTree& other);
// no implementation
int32 _CompareKeys(const void* key1, int keylength1,
@@ -246,8 +251,8 @@ class BPlusTree {
status_t _InsertDuplicate(Transaction& transaction,
CachedNode& cached, const bplustree_node* node,
uint16 index, off_t value);
void _InsertKey(bplustree_node *node, uint16 index, uint8 *key,
uint16 keyLength, off_t value);
void _InsertKey(bplustree_node* node, uint16 index,
uint8* key, uint16 keyLength, off_t value);
status_t _SplitNode(bplustree_node* node, off_t nodeOffset,
bplustree_node* other, off_t otherOffset,
uint16* _keyIndex, uint8* key, uint16* _keyLength,
@@ -274,7 +279,7 @@ class BPlusTree {
bool fAllowDuplicates;
status_t fStatus;
mutex fIteratorLock;
Chain<TreeIterator> fIterators;
SinglyLinkedList<TreeIterator> fIterators;
};
@@ -283,7 +288,7 @@ class BPlusTree {
extern int32 compareKeys(type_code type, const void* key1, int keyLength1,
const void* key2, int keyLength2);
class TreeIterator {
class TreeIterator : public SinglyLinkedListLinkImpl<TreeIterator> {
public:
TreeIterator(BPlusTree* tree);
~TreeIterator();
@@ -295,8 +300,9 @@ class TreeIterator {
status_t Find(const uint8* key, uint16 keyLength);
status_t Rewind();
status_t GetNextEntry(void *key, uint16 *keyLength, uint16 maxLength,
off_t *value, uint16 *duplicate = NULL);
status_t GetNextEntry(void* key, uint16* keyLength,
uint16 maxLength, off_t* value,
uint16* duplicate = NULL);
status_t GetPreviousEntry(void* key, uint16* keyLength,
uint16 maxLength, off_t* value,
uint16* duplicate = NULL);
@@ -307,22 +313,21 @@ class TreeIterator {
#endif
private:
BPlusTree *fTree;
friend class BPlusTree;
off_t fCurrentNodeOffset; // traverse position
// called by BPlusTree
void Update(off_t offset, off_t nextOffset, uint16 keyIndex,
uint16 splitAt, int8 change);
void Stop();
private:
BPlusTree* fTree;
off_t fCurrentNodeOffset;
// traverse position
int32 fCurrentKey;
off_t fDuplicateNode;
uint16 fDuplicate, fNumDuplicates;
bool fIsFragment;
private:
friend class Chain<TreeIterator>;
friend class BPlusTree;
void Update(off_t offset, off_t nextOffset, uint16 keyIndex,
uint16 splitAt, int8 change);
void Stop();
TreeIterator *fNext;
};
@@ -487,15 +492,14 @@ bplustree_node::IsLeaf() const
inline duplicate_array*
bplustree_node::FragmentAt(int8 index) const
{
return (duplicate_array *)((off_t *)this
+ index * (NUM_FRAGMENT_VALUES + 1));
return (duplicate_array*)((off_t*)this + index * (NUM_FRAGMENT_VALUES + 1));
}
inline duplicate_array*
bplustree_node::DuplicateArray() const
{
return (duplicate_array *)&this->overflow_link;
return (duplicate_array*)&overflow_link;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2007, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
* This file may be used under the terms of the MIT License.
*/
#ifndef CACHED_BLOCK_H
@@ -12,7 +12,6 @@
#include "Volume.h"
#include "Journal.h"
#include "Chain.h"
#include "Debug.h"
@@ -49,8 +48,8 @@ class CachedBlock {
uint32 BlockShift() const { return fVolume->BlockShift(); }
private:
CachedBlock(const CachedBlock &);
CachedBlock &operator=(const CachedBlock &);
CachedBlock(const CachedBlock& other);
CachedBlock& operator=(const CachedBlock& other);
// no implementation
protected:
@@ -197,5 +196,4 @@ CachedBlock::MakeWritable(Transaction &transaction)
transaction.ID());
}
#endif /* CACHED_BLOCK_H */
#endif // CACHED_BLOCK_H
@@ -1,56 +0,0 @@
#ifndef CHAIN_H
#define CHAIN_H
/* Chain - a chain implementation; it's used for the callback management
** throughout the code (currently TreeIterator, and AttributeIterator).
**
** Initial version by Axel Dörfler, axeld@pinc-software.de
** This file may be used under the terms of the OpenBeOS License.
*/
#include "system_dependencies.h"
/** The Link class you want to use with the Chain class needs to have
* a "fNext" member which is accessable from within the Chain class.
*/
template<class Link> class Chain {
public:
Chain()
:
fFirst(NULL)
{
}
void Add(Link *link)
{
link->fNext = fFirst;
fFirst = link;
}
void Remove(Link *link)
{
// search list for the correct callback to remove
Link *last = NULL,*entry;
for (entry = fFirst;link != entry;entry = entry->fNext)
last = entry;
if (link == entry) {
if (last)
last->fNext = link->fNext;
else
fFirst = link->fNext;
}
}
Link *Next(Link *last)
{
if (last == NULL)
return fFirst;
return last->fNext;
}
private:
Link *fFirst;
};
#endif /* CHAIN_H */
@@ -596,9 +596,10 @@ Inode::_RemoveSmallData(bfs_inode *node, small_data *item, int32 index)
memset(item, 0, item->Size());
// update all current iterators
AttributeIterator *iterator = NULL;
while ((iterator = fIterators.Next(iterator)) != NULL) {
iterator->Update(index, -1);
SinglyLinkedList<AttributeIterator>::Iterator iterator
= fIterators.GetIterator();
while (iterator.HasNext()) {
iterator.Next()->Update(index, -1);
}
return B_OK;
@@ -780,9 +781,10 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter,
memset(item, 0, (uint8 *)node + fVolume->InodeSize() - (uint8 *)item);
// update all current iterators
AttributeIterator *iterator = NULL;
while ((iterator = fIterators.Next(iterator)) != NULL) {
iterator->Update(index, 1);
SinglyLinkedList<AttributeIterator>::Iterator iterator
= fIterators.GetIterator();
while (iterator.HasNext()) {
iterator.Next()->Update(index, 1);
}
return B_OK;
@@ -2356,7 +2358,7 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name,
return B_IS_A_DIRECTORY;
// we want to open the file, so we should have the rights to do so
if (inode->CheckPermissions(openModeToAccess(openMode)) != B_OK)
if (inode->CheckPermissions(open_mode_to_access(openMode)) != B_OK)
return B_NOT_ALLOWED;
if (openMode & O_TRUNC) {
+2 -5
View File
@@ -9,7 +9,6 @@
#include "system_dependencies.h"
#include "CachedBlock.h"
#include "Chain.h"
#include "Debug.h"
#include "Journal.h"
#include "Volume.h"
@@ -236,7 +235,7 @@ private:
// the correct keys from the indices
mutable recursive_lock fSmallDataLock;
Chain<AttributeIterator> fIterators;
SinglyLinkedList<AttributeIterator> fIterators;
};
#if _KERNEL_MODE && KDEBUG
@@ -384,7 +383,7 @@ private:
};
class AttributeIterator {
class AttributeIterator : public SinglyLinkedListLinkImpl<AttributeIterator> {
public:
AttributeIterator(Inode* inode);
~AttributeIterator();
@@ -394,13 +393,11 @@ public:
ino_t* id);
private:
friend class Chain<AttributeIterator>;
friend class Inode;
void Update(uint16 index, int8 change);
private:
AttributeIterator* fNext;
int32 fCurrentSmallData;
Inode* fInode;
Inode* fAttributes;
@@ -13,7 +13,6 @@
#endif
#include "Volume.h"
#include "Chain.h"
#include "Utility.h"
+13 -16
View File
@@ -1,6 +1,5 @@
/* Query - query parsing and evaluation
*
* Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de.
/*
* Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
* This file may be used under the terms of the MIT License.
*/
#ifndef QUERY_H
@@ -8,9 +7,9 @@
#include "system_dependencies.h"
#include "Chain.h"
#include "Index.h"
class Volume;
class Term;
class Equation;
@@ -35,25 +34,28 @@ class Expression {
bool IsOperator(char** expr, char op);
private:
Expression(const Expression &);
Expression &operator=(const Expression &);
Expression(const Expression& other);
Expression& operator=(const Expression& other);
// no implementation
char* fPosition;
Term* fTerm;
};
class Query {
class Query : public SinglyLinkedListLinkImpl<Query> {
public:
Query(Volume *volume, Expression *expression, uint32 flags);
Query(Volume* volume, Expression* expression,
uint32 flags);
~Query();
status_t Rewind();
status_t GetNextEntry(struct dirent* , size_t size);
void SetLiveMode(port_id port, int32 token);
void LiveUpdate(Inode *inode, const char *attribute, int32 type,
const uint8 *oldKey, size_t oldLength, const uint8 *newKey, size_t newLength);
void LiveUpdate(Inode* inode, const char* attribute,
int32 type, const uint8* oldKey,
size_t oldLength, const uint8* newKey,
size_t newLength);
Expression* GetExpression() const { return fExpression; }
@@ -68,11 +70,6 @@ class Query {
uint32 fFlags;
port_id fPort;
int32 fToken;
private:
friend class Chain<Query>;
Query *fNext;
};
#endif /* QUERY_H */
#endif // QUERY_H
@@ -64,7 +64,7 @@ is_directory(int mode)
file, it will be converted to R_OK.
*/
inline int
openModeToAccess(int openMode)
open_mode_to_access(int openMode)
{
openMode &= O_RWMASK;
if (openMode == O_RDONLY)
@@ -526,8 +526,9 @@ Volume::UpdateLiveQueries(Inode* inode, const char* attribute, int32 type,
{
MutexLocker _(fQueryLock);
Query* query = NULL;
while ((query = fQueries.Next(query)) != NULL) {
SinglyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
while (iterator.HasNext()) {
Query* query = iterator.Next();
query->LiveUpdate(inode, attribute, type, oldKey, oldLength, newKey,
newLength);
}
+1 -2
View File
@@ -10,7 +10,6 @@
#include "bfs.h"
#include "BlockAllocator.h"
#include "Chain.h"
class Journal;
class Inode;
@@ -129,7 +128,7 @@ class Volume {
vint32 fDirtyCachedBlocks;
mutex fQueryLock;
Chain<Query> fQueries;
SinglyLinkedList<Query> fQueries;
int32 fUniqueID;
uint32 fFlags;
@@ -1107,7 +1107,7 @@ bfs_open(fs_volume *_volume, fs_vnode *_node, int openMode, void **_cookie)
//return B_IS_A_DIRECTORY;
}
status_t status = inode->CheckPermissions(openModeToAccess(openMode)
status_t status = inode->CheckPermissions(open_mode_to_access(openMode)
| (openMode & O_TRUNC ? W_OK : 0));
if (status < B_OK)
RETURN_ERROR(status);