aboutsummaryrefslogtreecommitdiff
path: root/sys/nmemio/minit.x
blob: 06214137d3af95309bb750107469a8f5de9ec608 (plain) (blame)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include <syserr.h>
include	<config.h>


define  L_SENTINAL      20030125
define  U_SENTINAL      20040922


# MEM_INIT -- Initialize the MEMIO interface for the task.

procedure mem_init (task)

char	task[ARB]			# task name

int	mgtenv()

include "nmemio.com"

begin
	# Initialize I/O buffers for stdout/stderr.  We do this here to
	# create the file buffers without counting these in the memory 
	# usage stats.
#	call fmkbfs (STDOUT)
#	call fmkbfs (STDERR)

	# Allocate the garbage collection buffer.
	mcollect  = mgtenv ("MEMIO_COLLECT")
	call mgc_init()

	# Initialize the sentinal values.
	lsentinal   = L_SENTINAL
	usentinal   = U_SENTINAL

	mwatch    = mgtenv ("MEMIO_WATCH")
	mreport   = mgtenv ("MEMIO_REPORT")
	mclear    = mgtenv ("MEMIO_CLEAR")
	mdebug    = mgtenv ("MEMIO_DEBUG")

	max_alloc = 0
	mem_used  = 0
	leaked	  = 0
	nleaked	  = 0
	nalloc	  = 0
	nfree	  = 0

	in_task	  = 1
end


# MGTENV -- Get an environment variable for MEMIO control.

int procedure mgtenv (varname)

char	varname[ARB]			# env variable to find

int	ival, ip, status, junk
char	key[SZ_LINE], value[SZ_LINE]

int	ctoi()

begin
	ip = 1				# init
        ival = 0
	call aclrc (key, SZ_LINE)
	call aclrc (value, SZ_LINE)

        call strpak (varname, key, SZ_LINE)
        call zgtenv (key, value, SZ_LINE, status)
        call strupk (value, value, SZ_LINE)

	if (status == 0)		# variable defined w/out value
	    ival = 1
	else if (status > 0)		# get environment variable value
	    junk = ctoi (value, ip, ival)

	return (ival)
end


# MEM_PTYPE -- Print a pointer type.  Used in error messages.

procedure mem_ptype (dtype)

int     dtype

begin
	switch (dtype) {
	case TY_BOOL:       call pargstr ("TY_BOOL")
	case TY_CHAR:       call pargstr ("TY_CHAR")
	case TY_SHORT:      call pargstr ("TY_SHORT")
	case TY_INT:        call pargstr ("TY_INT")
	case TY_LONG:       call pargstr ("TY_LONG")
	case TY_REAL:       call pargstr ("TY_REAL")
	case TY_DOUBLE:     call pargstr ("TY_DOUBLE")
	case TY_COMPLEX:    call pargstr ("TY_COMPLEX")
	case TY_STRUCT:     call pargstr ("TY_STRUCT")
	case TY_POINTER:    call pargstr ("TY_POINTER")
	default:    	    call pargstr ("unknown")
	}
end


# MIO_INIT -- Initialize the MEMIO interface for the task.

procedure mio_init ()

include "nmemio.com"

begin
	mgc       = NULL
	mcollect  = 0
	mwatch    = 0
	mreport   = 0
	mclear    = 0
	mdebug    = 0

	max_alloc = 0
	mem_used  = 0
	leaked	  = 0
	nleaked	  = 0
	nalloc	  = 0
	nfree	  = 0

	in_task	  = 0
end