1 | /* $Id$ $Revision$ */ |
---|---|
2 | /* vim:set shiftwidth=4 ts=8: */ |
3 | |
4 | /************************************************************************* |
5 | * Copyright (c) 2011 AT&T Intellectual Property |
6 | * All rights reserved. This program and the accompanying materials |
7 | * are made available under the terms of the Eclipse Public License v1.0 |
8 | * which accompanies this distribution, and is available at |
9 | * http://www.eclipse.org/legal/epl-v10.html |
10 | * |
11 | * Contributors: See CVS logs. Details at http://www.graphviz.org/ |
12 | *************************************************************************/ |
13 | |
14 | #include "vmhdr.h" |
15 | |
16 | /* Clear out all allocated space. |
17 | ** |
18 | ** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94. |
19 | */ |
20 | int vmclear(Vmalloc_t * vm) |
21 | { |
22 | reg Seg_t *seg; |
23 | reg Seg_t *next; |
24 | reg Block_t *tp; |
25 | reg size_t size, s; |
26 | reg Vmdata_t *vd = vm->data; |
27 | |
28 | if (!(vd->mode & VM_TRUST)) { |
29 | if (ISLOCK(vd, 0)) |
30 | return -1; |
31 | SETLOCK(vd, 0); |
32 | } |
33 | |
34 | vd->free = vd->wild = NIL(Block_t *); |
35 | vd->pool = 0; |
36 | |
37 | if (vd->mode & (VM_MTBEST | VM_MTDEBUG | VM_MTPROFILE)) { |
38 | vd->root = NIL(Block_t *); |
39 | for (s = 0; s < S_TINY; ++s) |
40 | TINY(vd)[s] = NIL(Block_t *); |
41 | for (s = 0; s <= S_CACHE; ++s) |
42 | CACHE(vd)[s] = NIL(Block_t *); |
43 | } |
44 | |
45 | for (seg = vd->seg; seg; seg = next) { |
46 | next = seg->next; |
47 | |
48 | tp = SEGBLOCK(seg); |
49 | size = seg->baddr - ((Vmuchar_t *) tp) - 2 * sizeof(Head_t); |
50 | |
51 | SEG(tp) = seg; |
52 | SIZE(tp) = size; |
53 | if ((vd->mode & (VM_MTLAST | VM_MTPOOL))) |
54 | seg->free = tp; |
55 | else { |
56 | SIZE(tp) |= BUSY | JUNK; |
57 | LINK(tp) = CACHE(vd)[C_INDEX(SIZE(tp))]; |
58 | CACHE(vd)[C_INDEX(SIZE(tp))] = tp; |
59 | } |
60 | |
61 | tp = BLOCK(seg->baddr); |
62 | SEG(tp) = seg; |
63 | SIZE(tp) = BUSY; |
64 | } |
65 | |
66 | CLRLOCK(vd, 0); |
67 | return 0; |
68 | } |
69 |