1 /* $Id: log.c,v 1.4 1994/06/24 11:55:23 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".
11 /* Logical manipulations.
12 The chunks are properly chained in the physical chain.
15 privatedata mallink *free_list[MAX_FLIST+1];
18 link_free_chunk(register mallink *ml)
20 /* The free chunk ml is inserted in its proper logical
23 register mallink **mlp = &free_list[0];
24 register size_type n = size_of(ml);
25 register mallink *ml1;
27 assert(n < (1L << LOG_MAX_SIZE));
33 while (n >= MIN_SIZE);
36 set_log_prev(ml, MAL_NULL);
37 set_log_next(ml, ml1);
42 set_log_prev(ml1, ml);
49 unlink_free_chunk(register mallink *ml)
51 /* Unlinks a free chunk from (the middle of) the
54 register mallink *next = log_next_of(ml);
55 register mallink *prev = log_prev_of(ml);
58 /* it is the first in the chain */
59 register mallink **mlp = &free_list[-1];
60 register size_type n = size_of(ml);
62 assert(n < (1L << LOG_MAX_SIZE));
67 while (n >= MIN_SIZE);
71 set_log_next(prev, next);
75 set_log_prev(next, prev);
81 search_free_list(int class, size_t n)
83 /* Searches the free_list[class] for a chunk of at least size n;
84 since it is searching a slightly undersized list,
85 such a block may not be there.
89 for (ml = free_list[class]; ml; ml = log_next_of(ml))
92 return MAL_NULL; /* nothing found */
96 first_present(int class)
98 /* Find the index i in free_list[] such that:
99 i >= class && free_list[i] != MAL_NULL.
100 Return MAL_NULL if no such i exists;
101 Otherwise, return the first block of this list, after
104 register mallink **mlp, *ml;
106 for (mlp = &free_list[class]; mlp < &free_list[MAX_FLIST]; mlp++) {
107 if ((ml = *mlp) != MAL_NULL) {
109 *mlp = log_next_of(ml); /* may be MAL_NULL */
111 /* unhook backward link
113 set_log_prev(*mlp, MAL_NULL);
124 free_list_entry(int i) {
125 /* To allow maldump.c access to log.c's private data.