/**
 * \file
 * \brief Very simple slab allocator
 */

/*
 * Copyright (c) 2008, ETH Zurich.
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
 */

#ifndef LIBBARRELFISH_SIMPLESLAB_H
#define LIBBARRELFISH_SIMPLESLAB_H

#include <sys/cdefs.h>

__BEGIN_DECLS

// forward declarations
struct simpleslab_allocator;
struct simpleblock_head;

struct simpleslab_allocator {
    void *start, *end;
    uint32_t total, free;
    struct simpleblock_head *blocks;
};

void simpleslab_init(struct simpleslab_allocator *slabs, size_t blocksize, void *buf, size_t buflen);
void *simpleslab_alloc(struct simpleslab_allocator *slabs);
void simpleslab_free(struct simpleslab_allocator *slabs, void *block);

// size of block header
#define SIMPLESLAB_BLOCK_HDRSIZE (sizeof(void *))
// should be able to fit the header into the block


__END_DECLS

#endif // LIBBARRELFISH_SIMPLESLAB_H
