haiku/headers/private/kernel/slab/Utilities.h
Hugo Santos 81423c91c7 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
2007-04-26 03:41:24 +00:00

46 lines
1.1 KiB
C++

/*
* Copyright 2007, Hugo Santos. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Hugo Santos, hugosantos@gmail.com
*/
#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