File: vmclose.c

package info (click to toggle)
graphviz 2.8-3%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 20,480 kB
  • ctags: 22,071
  • sloc: ansic: 163,260; cpp: 36,565; sh: 25,024; yacc: 2,358; tcl: 1,808; makefile: 1,745; cs: 805; perl: 801; ml: 649; awk: 160; lex: 153; python: 105; ruby: 32; php: 6
file content (85 lines) | stat: -rw-r--r-- 2,391 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* $Id: vmclose.c,v 1.1.1.1 2004/12/23 04:04:24 ellson Exp $ $Revision: 1.1.1.1 $ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

#include	"vmhdr.h"

/*	Close down a region.
**
**	Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
*/
#if __STD_C
int vmclose(Vmalloc_t * vm)
#else
int vmclose(vm)
Vmalloc_t *vm;
#endif
{
    reg Seg_t *seg, *vmseg;
    reg Vmemory_f memoryf;
    reg Vmdata_t *vd = vm->data;
    reg Vmalloc_t *v, *last;

    if (vm == Vmheap)
	return -1;

    if (!(vd->mode & VM_TRUST) && ISLOCK(vd, 0))
	return -1;

    if (vm->disc->exceptf &&
	(*vm->disc->exceptf) (vm, VM_CLOSE, NIL(Void_t *), vm->disc) < 0)
	return -1;

    /* make this region inaccessible until it disappears */
    vd->mode &= ~VM_TRUST;
    SETLOCK(vd, 0);

    if ((vd->mode & VM_MTPROFILE) && _Vmpfclose)
	(*_Vmpfclose) (vm);

    /* remove from linked list of regions   */
    for (last = Vmheap, v = last->next; v; last = v, v = v->next) {
	if (v == vm) {
	    last->next = v->next;
	    break;
	}
    }

    /* free all non-region segments */
    memoryf = vm->disc->memoryf;
    vmseg = NIL(Seg_t *);
    for (seg = vd->seg; seg;) {
	reg Seg_t *next = seg->next;
	if (seg->extent != seg->size)
	    (void) (*memoryf) (vm, seg->addr, seg->extent, 0, vm->disc);
	else
	    vmseg = seg;
	seg = next;
    }

    /* this must be done here because even though this region is freed,
       there may still be others that share this space.
     */
    CLRLOCK(vd, 0);

    /* free the segment that contains the region data */
    if (vmseg)
	(void) (*memoryf) (vm, vmseg->addr, vmseg->extent, 0, vm->disc);

    /* free the region itself */
    vmfree(Vmheap, vm);

    return 0;
}