added initial slab code to the kernel. It is still unused, and there is still no VM interaction.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20832 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2007, Hugo Santos. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hugo Santos, [email protected]
|
||||
*/
|
||||
|
||||
#ifndef _SLAB_UTILITIES_H_
|
||||
#define _SLAB_UTILITIES_H_
|
||||
|
||||
#include <slab/Base.h>
|
||||
#include <slab/MergedStrategy.h>
|
||||
|
||||
|
||||
template<typename Type, typename Backend>
|
||||
class TypedCache : public Cache< MergedLinkCacheStrategy<Backend> > {
|
||||
public:
|
||||
typedef MergedLinkCacheStrategy<Backend> Strategy;
|
||||
typedef Cache<Strategy> BaseType;
|
||||
|
||||
TypedCache(const char *name, size_t alignment)
|
||||
: BaseType(name, sizeof(Type), alignment, _ConstructObject,
|
||||
_DestructObject, this) {}
|
||||
virtual ~TypedCache() {}
|
||||
|
||||
Type *Alloc(uint32_t flags) { return (Type *)BaseType::AllocateObject(flags); }
|
||||
void Free(Type *object) { BaseType::ReturnObject(object); }
|
||||
|
||||
private:
|
||||
static void _ConstructObject(void *cookie, void *object)
|
||||
{
|
||||
((TypedCache *)cookie)->ConstructObject((Type *)object);
|
||||
}
|
||||
|
||||
static void _DestructObject(void *cookie, void *object)
|
||||
{
|
||||
((TypedCache *)cookie)->DestructObject((Type *)object);
|
||||
}
|
||||
|
||||
virtual void ConstructObject(Type *object) {}
|
||||
virtual void DestructObject(Type *object) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user