Merge branch 'release/0.0'
[allocwithin] / allocwithin_int.h
1 #ifndef __ALLOCWITHIN_INT_H__
2 #define __ALLOCWITHIN_INT_H__
3
4 /**
5 * $Id$
6 */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #ifdef HAVE_STDLIB_H
13 #include <stdlib.h>
14 #endif
15 #ifdef HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18 #ifdef HAVE_SIGNAL_H
19 #include <signal.h>
20 #endif
21 #ifdef HAVE_LIBPTHREAD
22 #include <pthread.h>
23 #endif
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27 #ifdef STDC_HEADERS
28 #include <stdio.h>
29 #include <errno.h>
30 #endif
31
32 #include "allocwithin.h"
33
34 #ifdef HAVE___ATTRIBUTE__
35 #define UNUSED __attribute__((__unused__))
36 #endif
37
38 struct allocw_block_
39 {
40 size_t size; /* total bytes of this block, including this header struct */
41 allocw_id_t next_off; /* byte-offset of next block, from start-of-region */
42 allocw_id_t prev_off; /* byte-offset of prev block, from start-of-region */
43 char data_[]; /* user data follows this header struct */
44 };
45
46 struct allocw_region_
47 {
48 size_t size; /* total bytes of this region, including this header struct */
49 allocw_id_t free_start; /* first free block */
50 allocw_id_t free_end; /* last free block */
51 pthread_mutex_t freelist_mutex; /* mutex for accessing freelist */
52 unsigned int num_alloced; /* number of outstanding allocations */
53 char data_[]; /* blocks follow this header struct */
54 };
55
56 /* convert an id into a region to a pointer */
57 #define BLOCK_PTR(__region, __id) ( (struct allocw_block_ *)((char *)(__region) + (__id)) )
58
59 /* convert a pointer to a block in a region to an id */
60 #define BLOCK_OFF(__region, __block) ( (void *)(__block) - (void *)(__region) )
61
62 #endif /* __ALLOCWITHIN_INT_H__ */