haiku/headers/private/kernel/slab/Strategy.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

54 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_STRATEGY_H_
#define _SLAB_STRATEGY_H_
#include <slab/Base.h>
template<typename Backend>
class BaseCacheStrategy {
protected:
typedef cache_object_link ObjectLink;
typedef cache_slab BaseSlab;
BaseCacheStrategy(base_cache *parent)
: fParent(parent) {}
size_t SlabSize(size_t tailSpace) const
{
size_t pageCount = (kMinimumSlabItems * fParent->object_size
+ tailSpace) / Backend::kPageSize;
if (pageCount < 1)
pageCount = 1;
return pageCount * Backend::kPageSize;
}
struct Slab : BaseSlab {
typename Backend::AllocationID id;
};
BaseSlab *_ConstructSlab(Slab *slab, void *pages, size_t tailSpace,
ObjectLink *(*getLink)(void *parent, void *object), void *parent)
{
return base_cache_construct_slab(fParent, slab, pages,
SlabSize(tailSpace) - tailSpace, getLink, parent);
}
void _DestructSlab(BaseSlab *slab)
{
base_cache_destruct_slab(fParent, slab);
Backend::FreePages(fParent, ((Slab *)slab)->id);
}
base_cache *fParent;
};
#endif