00001
00002
00003
00004
00005
00006 #ifndef _tredmill_BLOCK_H
00007 #define _tredmill_BLOCK_H
00008
00009 #include "tredmill/list.h"
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 typedef struct tm_block {
00027
00028 tm_list list;
00029
00030 #if tm_block_GUARD
00031
00032 unsigned long guard1;
00033 #define tm_block_hash(b) (0xe8a624c0 ^ (unsigned long)(b))
00034 #endif
00035
00036 #if tm_name_GUARD
00037
00038 const char *name;
00039 #endif
00040
00041
00042 int id;
00043
00044
00045 size_t size;
00046
00047
00048
00049 struct tm_type *type;
00050
00051 char *begin;
00052
00053
00054 char *end;
00055
00056
00057 char *next_parcel;
00058
00059
00060
00061
00062
00063 size_t n[tm_CAPACITY + 1];
00064
00065 #if tm_block_GUARD
00066
00067 unsigned long guard2;
00068 #endif
00069
00070
00071 double alignment[0];
00072 } tm_block;
00073
00074
00075 #define tm_block_unused(b) ((b)->n[tm_WHITE] == b->n[tm_TOTAL])
00076
00077 #define tm_block_type(b) ((b)->type)
00078
00079
00080 #define tm_block_node_begin(b) ((void*) (b)->begin)
00081
00082
00083 #define tm_block_node_end(b) ((void*) (b)->end)
00084
00085
00086 #define tm_block_node_next_parcel(b) ((void*) (b)->next_parcel)
00087
00088
00089 #define tm_block_node_size(b) ((b)->type->size + tm_node_HDR_SIZE)
00090
00091
00092 #define tm_block_node_next(b, n) ((void*) (((char*) (n)) + tm_block_node_size(b)))
00093
00094 #if tm_block_GUARD
00095
00096 #define _tm_block_validate(b) do { \
00097 tm_assert_test(b); \
00098 tm_assert_test((b)->size); \
00099 tm_assert_test(! ((void*) &tm <= (void*) (b) && (void*) (b) < (void*) (&tm + 1))); \
00100 tm_assert_test((b)->guard1 == tm_block_hash(b)); \
00101 tm_assert_test((b)->guard2 == tm_block_hash(b)); \
00102 tm_assert_test((b)->begin < (b)->end); \
00103 tm_assert_test((b)->begin <= (b)->alloc && (b)->alloc <= (b)->end); \
00104 tm_assert_test((b)->n[tm_WHITE] + (b)->n[tm_ECRU] + (b)->n[tm_GREY] + (b)->n[tm_BLACK] == (b)->n[tm_TOTAL]); \
00105 } while(0)
00106 #else
00107 #define _tm_block_validate(b) ((void) 0)
00108 #endif
00109
00110
00111
00112
00113 #endif