* 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")*/) || !strcmp(name, "size")*/)
RETURN_ERROR(B_NOT_ALLOWED); RETURN_ERROR(B_NOT_ALLOWED);
return fInode->CheckPermissions(openModeToAccess(openMode) return fInode->CheckPermissions(open_mode_to_access(openMode)
| (openMode & O_TRUNC ? W_OK : 0)); | (openMode & O_TRUNC ? W_OK : 0));
} }
@@ -377,9 +377,10 @@ BPlusTree::~BPlusTree()
// traversing the tree - a TreeIterator doesn't lock the inode) // traversing the tree - a TreeIterator doesn't lock the inode)
mutex_lock(&fIteratorLock); mutex_lock(&fIteratorLock);
TreeIterator *iterator = NULL; SinglyLinkedList<TreeIterator>::Iterator iterator
while ((iterator = fIterators.Next(iterator)) != NULL) = fIterators.GetIterator();
iterator->Stop(); while (iterator.HasNext())
iterator.Next()->Stop();
mutex_destroy(&fIteratorLock); 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 // any time, so we need to protect this loop
MutexLocker _(fIteratorLock); MutexLocker _(fIteratorLock);
TreeIterator *iterator = NULL; SinglyLinkedList<TreeIterator>::Iterator iterator
while ((iterator = fIterators.Next(iterator)) != NULL) = fIterators.GetIterator();
iterator->Update(offset, nextOffset, keyIndex, splitAt, change); 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) TreeIterator::TreeIterator(BPlusTree *tree)
: :
fTree(tree), fTree(tree),
fCurrentNodeOffset(BPLUSTREE_NULL), fCurrentNodeOffset(BPLUSTREE_NULL)
fNext(NULL)
{ {
tree->_AddIterator(this); tree->_AddIterator(this);
} }
+33 -29
View File
@@ -8,7 +8,6 @@
#include "bfs.h" #include "bfs.h"
#include "Journal.h" #include "Journal.h"
#include "Chain.h"
// #pragma mark - on-disk structures // #pragma mark - on-disk structures
@@ -212,12 +211,18 @@ class BPlusTree {
off_t value); off_t value);
status_t Insert(Transaction& transaction, const char* key, status_t Insert(Transaction& transaction, const char* key,
off_t value); off_t value);
status_t Insert(Transaction &transaction, int32 key, off_t value); status_t Insert(Transaction& transaction, int32 key,
status_t Insert(Transaction &transaction, uint32 key, off_t value); off_t value);
status_t Insert(Transaction &transaction, int64 key, off_t value); status_t Insert(Transaction& transaction, uint32 key,
status_t Insert(Transaction &transaction, uint64 key, off_t value); off_t value);
status_t Insert(Transaction &transaction, float key, off_t value); status_t Insert(Transaction& transaction, int64 key,
status_t Insert(Transaction &transaction, double key, off_t value); 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, status_t Replace(Transaction& transaction, const uint8* key,
uint16 keyLength, off_t value); uint16 keyLength, off_t value);
@@ -227,8 +232,8 @@ class BPlusTree {
static int32 ModeToKeyType(mode_t mode); static int32 ModeToKeyType(mode_t mode);
private: private:
BPlusTree(const BPlusTree &); BPlusTree(const BPlusTree& other);
BPlusTree &operator=(const BPlusTree &); BPlusTree& operator=(const BPlusTree& other);
// no implementation // no implementation
int32 _CompareKeys(const void* key1, int keylength1, int32 _CompareKeys(const void* key1, int keylength1,
@@ -246,8 +251,8 @@ class BPlusTree {
status_t _InsertDuplicate(Transaction& transaction, status_t _InsertDuplicate(Transaction& transaction,
CachedNode& cached, const bplustree_node* node, CachedNode& cached, const bplustree_node* node,
uint16 index, off_t value); uint16 index, off_t value);
void _InsertKey(bplustree_node *node, uint16 index, uint8 *key, void _InsertKey(bplustree_node* node, uint16 index,
uint16 keyLength, off_t value); uint8* key, uint16 keyLength, off_t value);
status_t _SplitNode(bplustree_node* node, off_t nodeOffset, status_t _SplitNode(bplustree_node* node, off_t nodeOffset,
bplustree_node* other, off_t otherOffset, bplustree_node* other, off_t otherOffset,
uint16* _keyIndex, uint8* key, uint16* _keyLength, uint16* _keyIndex, uint8* key, uint16* _keyLength,
@@ -274,7 +279,7 @@ class BPlusTree {
bool fAllowDuplicates; bool fAllowDuplicates;
status_t fStatus; status_t fStatus;
mutex fIteratorLock; 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, extern int32 compareKeys(type_code type, const void* key1, int keyLength1,
const void* key2, int keyLength2); const void* key2, int keyLength2);
class TreeIterator { class TreeIterator : public SinglyLinkedListLinkImpl<TreeIterator> {
public: public:
TreeIterator(BPlusTree* tree); TreeIterator(BPlusTree* tree);
~TreeIterator(); ~TreeIterator();
@@ -295,8 +300,9 @@ class TreeIterator {
status_t Find(const uint8* key, uint16 keyLength); status_t Find(const uint8* key, uint16 keyLength);
status_t Rewind(); status_t Rewind();
status_t GetNextEntry(void *key, uint16 *keyLength, uint16 maxLength, status_t GetNextEntry(void* key, uint16* keyLength,
off_t *value, uint16 *duplicate = NULL); uint16 maxLength, off_t* value,
uint16* duplicate = NULL);
status_t GetPreviousEntry(void* key, uint16* keyLength, status_t GetPreviousEntry(void* key, uint16* keyLength,
uint16 maxLength, off_t* value, uint16 maxLength, off_t* value,
uint16* duplicate = NULL); uint16* duplicate = NULL);
@@ -307,22 +313,21 @@ class TreeIterator {
#endif #endif
private: 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; int32 fCurrentKey;
off_t fDuplicateNode; off_t fDuplicateNode;
uint16 fDuplicate, fNumDuplicates; uint16 fDuplicate, fNumDuplicates;
bool fIsFragment; 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* inline duplicate_array*
bplustree_node::FragmentAt(int8 index) const bplustree_node::FragmentAt(int8 index) const
{ {
return (duplicate_array *)((off_t *)this return (duplicate_array*)((off_t*)this + index * (NUM_FRAGMENT_VALUES + 1));
+ index * (NUM_FRAGMENT_VALUES + 1));
} }
inline duplicate_array* inline duplicate_array*
bplustree_node::DuplicateArray() const 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. * This file may be used under the terms of the MIT License.
*/ */
#ifndef CACHED_BLOCK_H #ifndef CACHED_BLOCK_H
@@ -12,7 +12,6 @@
#include "Volume.h" #include "Volume.h"
#include "Journal.h" #include "Journal.h"
#include "Chain.h"
#include "Debug.h" #include "Debug.h"
@@ -49,8 +48,8 @@ class CachedBlock {
uint32 BlockShift() const { return fVolume->BlockShift(); } uint32 BlockShift() const { return fVolume->BlockShift(); }
private: private:
CachedBlock(const CachedBlock &); CachedBlock(const CachedBlock& other);
CachedBlock &operator=(const CachedBlock &); CachedBlock& operator=(const CachedBlock& other);
// no implementation // no implementation
protected: protected:
@@ -197,5 +196,4 @@ CachedBlock::MakeWritable(Transaction &transaction)
transaction.ID()); 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()); memset(item, 0, item->Size());
// update all current iterators // update all current iterators
AttributeIterator *iterator = NULL; SinglyLinkedList<AttributeIterator>::Iterator iterator
while ((iterator = fIterators.Next(iterator)) != NULL) { = fIterators.GetIterator();
iterator->Update(index, -1); while (iterator.HasNext()) {
iterator.Next()->Update(index, -1);
} }
return B_OK; return B_OK;
@@ -780,9 +781,10 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter,
memset(item, 0, (uint8 *)node + fVolume->InodeSize() - (uint8 *)item); memset(item, 0, (uint8 *)node + fVolume->InodeSize() - (uint8 *)item);
// update all current iterators // update all current iterators
AttributeIterator *iterator = NULL; SinglyLinkedList<AttributeIterator>::Iterator iterator
while ((iterator = fIterators.Next(iterator)) != NULL) { = fIterators.GetIterator();
iterator->Update(index, 1); while (iterator.HasNext()) {
iterator.Next()->Update(index, 1);
} }
return B_OK; return B_OK;
@@ -2356,7 +2358,7 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name,
return B_IS_A_DIRECTORY; return B_IS_A_DIRECTORY;
// we want to open the file, so we should have the rights to do so // 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; return B_NOT_ALLOWED;
if (openMode & O_TRUNC) { if (openMode & O_TRUNC) {
+2 -5
View File
@@ -9,7 +9,6 @@
#include "system_dependencies.h" #include "system_dependencies.h"
#include "CachedBlock.h" #include "CachedBlock.h"
#include "Chain.h"
#include "Debug.h" #include "Debug.h"
#include "Journal.h" #include "Journal.h"
#include "Volume.h" #include "Volume.h"
@@ -236,7 +235,7 @@ private:
// the correct keys from the indices // the correct keys from the indices
mutable recursive_lock fSmallDataLock; mutable recursive_lock fSmallDataLock;
Chain<AttributeIterator> fIterators; SinglyLinkedList<AttributeIterator> fIterators;
}; };
#if _KERNEL_MODE && KDEBUG #if _KERNEL_MODE && KDEBUG
@@ -384,7 +383,7 @@ private:
}; };
class AttributeIterator { class AttributeIterator : public SinglyLinkedListLinkImpl<AttributeIterator> {
public: public:
AttributeIterator(Inode* inode); AttributeIterator(Inode* inode);
~AttributeIterator(); ~AttributeIterator();
@@ -394,13 +393,11 @@ public:
ino_t* id); ino_t* id);
private: private:
friend class Chain<AttributeIterator>;
friend class Inode; friend class Inode;
void Update(uint16 index, int8 change); void Update(uint16 index, int8 change);
private: private:
AttributeIterator* fNext;
int32 fCurrentSmallData; int32 fCurrentSmallData;
Inode* fInode; Inode* fInode;
Inode* fAttributes; Inode* fAttributes;
@@ -13,7 +13,6 @@
#endif #endif
#include "Volume.h" #include "Volume.h"
#include "Chain.h"
#include "Utility.h" #include "Utility.h"
+13 -16
View File
@@ -1,6 +1,5 @@
/* Query - query parsing and evaluation /*
* * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de.
* This file may be used under the terms of the MIT License. * This file may be used under the terms of the MIT License.
*/ */
#ifndef QUERY_H #ifndef QUERY_H
@@ -8,9 +7,9 @@
#include "system_dependencies.h" #include "system_dependencies.h"
#include "Chain.h"
#include "Index.h" #include "Index.h"
class Volume; class Volume;
class Term; class Term;
class Equation; class Equation;
@@ -35,25 +34,28 @@ class Expression {
bool IsOperator(char** expr, char op); bool IsOperator(char** expr, char op);
private: private:
Expression(const Expression &); Expression(const Expression& other);
Expression &operator=(const Expression &); Expression& operator=(const Expression& other);
// no implementation // no implementation
char* fPosition; char* fPosition;
Term* fTerm; Term* fTerm;
}; };
class Query { class Query : public SinglyLinkedListLinkImpl<Query> {
public: public:
Query(Volume *volume, Expression *expression, uint32 flags); Query(Volume* volume, Expression* expression,
uint32 flags);
~Query(); ~Query();
status_t Rewind(); status_t Rewind();
status_t GetNextEntry(struct dirent* , size_t size); status_t GetNextEntry(struct dirent* , size_t size);
void SetLiveMode(port_id port, int32 token); void SetLiveMode(port_id port, int32 token);
void LiveUpdate(Inode *inode, const char *attribute, int32 type, void LiveUpdate(Inode* inode, const char* attribute,
const uint8 *oldKey, size_t oldLength, const uint8 *newKey, size_t newLength); int32 type, const uint8* oldKey,
size_t oldLength, const uint8* newKey,
size_t newLength);
Expression* GetExpression() const { return fExpression; } Expression* GetExpression() const { return fExpression; }
@@ -68,11 +70,6 @@ class Query {
uint32 fFlags; uint32 fFlags;
port_id fPort; port_id fPort;
int32 fToken; 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. file, it will be converted to R_OK.
*/ */
inline int inline int
openModeToAccess(int openMode) open_mode_to_access(int openMode)
{ {
openMode &= O_RWMASK; openMode &= O_RWMASK;
if (openMode == O_RDONLY) if (openMode == O_RDONLY)
@@ -526,8 +526,9 @@ Volume::UpdateLiveQueries(Inode* inode, const char* attribute, int32 type,
{ {
MutexLocker _(fQueryLock); MutexLocker _(fQueryLock);
Query* query = NULL; SinglyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
while ((query = fQueries.Next(query)) != NULL) { while (iterator.HasNext()) {
Query* query = iterator.Next();
query->LiveUpdate(inode, attribute, type, oldKey, oldLength, newKey, query->LiveUpdate(inode, attribute, type, oldKey, oldLength, newKey,
newLength); newLength);
} }
+1 -2
View File
@@ -10,7 +10,6 @@
#include "bfs.h" #include "bfs.h"
#include "BlockAllocator.h" #include "BlockAllocator.h"
#include "Chain.h"
class Journal; class Journal;
class Inode; class Inode;
@@ -129,7 +128,7 @@ class Volume {
vint32 fDirtyCachedBlocks; vint32 fDirtyCachedBlocks;
mutex fQueryLock; mutex fQueryLock;
Chain<Query> fQueries; SinglyLinkedList<Query> fQueries;
int32 fUniqueID; int32 fUniqueID;
uint32 fFlags; uint32 fFlags;
@@ -1107,7 +1107,7 @@ bfs_open(fs_volume *_volume, fs_vnode *_node, int openMode, void **_cookie)
//return B_IS_A_DIRECTORY; //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)); | (openMode & O_TRUNC ? W_OK : 0));
if (status < B_OK) if (status < B_OK)
RETURN_ERROR(status); RETURN_ERROR(status);