1 /* $Id: phys.h,v 1.8 1994/06/24 11:18:07 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
6 /* Algorithms to manipulate the doubly-linked list of physical
9 publicdata mallink *ml_last;
14 #define BITS (FREE_BIT|STORE_BIT)
16 #define BITS (FREE_BIT)
19 #define __bits(ml) ((int)((size_type)_phys_prev_of(ml) & BITS))
20 #define __free_of(ml) ((int)((size_type)_phys_prev_of(ml) & FREE_BIT))
21 #define __phys_prev_of(ml) ((mallink *)((size_type)_phys_prev_of(ml) & ~BITS))
22 #define prev_size_of(ml) ((char *)(ml) - \
23 (char *)__phys_prev_of(ml) - \
26 #define set_phys_prev(ml,e) \
27 (_phys_prev_of(ml) = (mallink *) ((char *)e + __bits(ml)))
31 #define phys_prev_of(ml) (mallink *) \
32 (first_mallink(ml) ? \
33 (char *)Error("phys_prev_of first_mallink %lx", "somewhere", (long)ml) : \
34 (char *)__phys_prev_of(ml) \
36 #else /* ndef CHECK */
37 #define phys_prev_of(ml) __phys_prev_of(ml)
40 #define first_mallink(ml) (int) (__phys_prev_of(ml) == 0)
41 #define last_mallink(ml) (int) ((ml) == ml_last)
43 /* There is an ambiguity in the semantics of phys_next_of: sometimes
44 one wants it to return MAL_NULL if there is no next chunk, at
45 other times one wants the address of the virtual chunk at the
46 end of memory. The present version returns the address of the
47 (virtual) chunk and relies on the user to test last_mallink(ml)
50 #define size_of(ml) (_this_size_of(ml) - mallink_size())
51 #define set_phys_next(ml,e) \
52 (_this_size_of(ml) = (size_type)((char *)(e) - (char *)(ml)))
53 #define phys_next_of(ml) (mallink *) ((char *)(ml) + _this_size_of(ml))
55 #define set_free(ml,e) \
56 (_phys_prev_of(ml) = (mallink *) \
57 ((e) ? (size_type) _phys_prev_of(ml) | FREE_BIT : \
58 (size_type) _phys_prev_of(ml) & ~FREE_BIT))
59 #define free_of(ml) (__free_of(ml))
61 #define coalesce_forw(ml,nxt) ( unlink_free_chunk(nxt), \
62 combine_chunks((ml), (nxt)))
64 #define coalesce_backw(ml,prv) ( unlink_free_chunk(prv), \
65 stopped_working_on(ml), \
66 combine_chunks((prv), (ml)), \
67 started_working_on(prv))
70 #define set_print(ml,e) (_print_of(ml) = (e))
71 #define print_of(ml) (_print_of(ml))
74 public truncate(), combine_chunks();
75 public mallink *create_chunk();