Fixed compatibility of output.
[AROS.git] / compiler / arossupport / include / rt.h
blob94431aa4ddfe8b34382924d5ce03045cf960c33e
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Resource Tracking
6 Lang: english
8 This file can be included more than once
9 */
11 /* Resource Tracking currently disabled on native platforms */
12 #if (AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
13 # undef ENABLE_RT
14 #endif
16 #ifndef ENABLE_RT
17 # define ENABLE_RT 0
18 #endif
20 #if ENABLE_RT || defined(RT_INTERNAL)
21 # ifndef EXEC_TYPES_H
22 # include <exec/types.h>
23 # endif
25 # ifndef AROS_RT_H
26 # define AROS_RT_H
27 /* Put code which must be defined only once here */
29 /* Resources */
30 enum
32 RTT_ALLOCMEM,
33 RTT_ALLOCVEC,
34 RTT_PORT,
35 RTT_LIBRARY,
36 RTT_FILE,
37 RTT_SCREEN, /* Screen before Window, so the windows are closed before the screen */
38 RTT_WINDOW,
40 /* Don't add anything below here !!! */
41 RTT_MAX
44 enum
46 RTTB_EXEC,
47 RTTO_PutMsg,
48 RTTO_GetMsg,
51 enum
53 RTTB_DOS,
54 RTTO_Read,
55 RTTO_Write,
58 enum
60 RTTB_INTUITION,
61 RTTO_OpenScreen,
62 RTTO_OpenScreenTags,
63 RTTO_OpenScreenTagList,
64 RTTO_ScreenToFront,
65 RTTO_ScreenToBack,
66 RTTO_OpenWindow,
67 RTTO_OpenWindowTags,
68 RTTO_OpenWindowTagList,
69 RTTO_WindowToFront,
70 RTTO_WindowToBack,
73 __BEGIN_DECLS
74 void RT_IntInitB (void);
75 void RT_IntInitE (void);
76 void RT_IntExitB (void);
77 void RT_IntExitE (void);
78 IPTR RT_IntAdd (int rtt, const char * file, int line, ...); /* Add a resource for tracking */
79 IPTR RT_IntCheck (int rtt, const char * file, int line, int op, ...); /* Check a resource before use */
80 IPTR RT_IntFree (int rtt, const char * file, int line, ...); /* Stop tracking of a resource */
81 void RT_IntEnter (const char * functionname, const char * filename, int line);
82 void RT_IntTrack (int rtt, const char * file, int line, APTR res, ...);
83 void RT_Leave (void);
84 __END_DECLS
86 # ifndef RT_INTERNAL
87 # define RT_Add(rtt, args...) RT_IntAdd (rtt, __FILE__, __LINE__, ##args)
88 # define RT_Check(rtt, op, args...) RT_IntCheck (rtt, __FILE__, __LINE__, op, ##args)
89 # define RT_Free(rtt, args...) RT_IntFree (rtt, __FILE__, __LINE__, ##args)
90 # define RT_Enter(fn) RT_IntEnter (fn,__FILE__, __LINE__)
91 # define RT_Track(rtt, res...) RT_IntTrack (rtt, __FILE__, __LINE__, ##res)
92 # endif /* ENABLE_RT */
93 # endif /* AROS_RT_H */
95 /* Add a resource for tracking which must not be freed. */
97 # if ENABLE_RT
98 # undef RT_INITEXEC
99 # undef RT_EXITEXEC
101 # if ENABLE_RT_EXEC
102 # ifndef PROTO_EXEC_H
103 # include <proto/exec.h>
104 # endif
106 __BEGIN_DECLS
107 void RT_InitExec (void);
108 void RT_ExitExec (void);
109 __END_DECLS
111 # define RT_INITEXEC RT_InitExec(),
112 # define RT_EXITEXEC RT_ExitExec(),
114 # undef AllocMem
115 # define AllocMem(size,flags) (APTR)RT_Add(RTT_ALLOCMEM,(size),(flags))
116 # undef FreeMem
117 # define FreeMem(ptr,size) (void)RT_Free(RTT_ALLOCMEM,(ptr),(size))
118 # undef AllocVec
119 # define AllocVec(size,flags) (APTR)RT_Add(RTT_ALLOCVEC,(size),(flags))
120 # undef FreeVec
121 # define FreeVec(ptr) (void)RT_Free(RTT_ALLOCVEC,(ptr))
122 # undef OpenLibrary
123 # define OpenLibrary(name,ver) (APTR)RT_Add(RTT_LIBRARY,(name),(ver))
124 # undef CloseLibrary
125 # define CloseLibrary(lib) (void)RT_Free(RTT_LIBRARY,(lib))
126 # undef CreateMsgPort
127 # define CreateMsgPort() (APTR)RT_Add(RTT_PORT,NULL,0)
128 # undef DeleteMsgPort
129 # define DeleteMsgPort(mp) (void)RT_Free(RTT_PORT,(mp))
130 # undef CreatePort
131 # define CreatePort(name,pri) (APTR)RT_Add(RTT_PORT,(name),(pri))
132 # undef DeletePort
133 # define DeletePort(mp) (void)RT_Free(RTT_PORT,(mp))
134 # undef PutMsg
135 # define PutMsg(mp,msg) (void)RT_Check(RTT_PORT,RTTO_PutMsg,(mp),(msg))
136 # undef GetMsg
137 # define GetMsg(mp) (struct Message *)RT_Check(RTT_PORT,RTTO_GetMsg,(mp))
138 # else
139 # define RT_INITEXEC
140 # define RT_EXITEXEC
141 # endif /* ENABLE_RT_EXEC */
143 # undef RT_INITDOS
144 # undef RT_EXITDOS
146 # if ENABLE_RT_DOS
147 # ifndef PROTO_DOS_H
148 # include <proto/dos.h>
149 # endif
151 __BEGIN_DECLS
152 void RT_InitDos (void);
153 void RT_ExitDos (void);
154 __END_DECLS
156 # define RT_INITDOS RT_InitDos(),
157 # define RT_EXITDOS RT_ExitDos(),
159 # undef Open
160 # define Open(path,mode) (BPTR)RT_Add(RTT_FILE,(path),(mode))
161 # undef Close
162 # define Close(fh) (void)RT_Free(RTT_FILE,(fh))
163 # undef Read
164 # define Read(fh,buffer,length) (LONG)RT_Check(RTT_FILE,RTTO_Read,(fh),(buffer),(length))
165 # undef Write
166 # define Write(fh,buffer,length) (LONG)RT_Check(RTT_FILE,RTTO_Write,(fh),(buffer),(length))
167 # else
168 # define RT_INITDOS
169 # define RT_EXITDOS
170 # endif /* ENABLE_RT_DOS */
172 # undef RT_INITINTUITION
173 # undef RT_EXITINTUITION
175 # if ENABLE_RT_INTUITION
176 # ifndef PROTO_INTUITION_H
177 # include <proto/intuition.h>
178 # endif
180 __BEGIN_DECLS
181 void RT_InitIntuition (void);
182 void RT_ExitIntuition (void);
183 __END_DECLS
185 # define RT_INITINTUITION RT_InitIntuition(),
186 # define RT_EXITINTUITION RT_ExitIntuition(),
188 # undef OpenScreen
189 # define OpenScreen(ns) (struct Screen *)RT_Add(RTT_SCREEN,RTTO_OpenScreen,(ns))
190 # undef OpenScreenTagList
191 # define OpenScreenTagList(ns,tl) (struct Screen *)RT_Add(RTT_SCREEN,RTTO_OpenScreenTagList,(ns),(tl))
192 # undef OpenScreenTags
193 # define OpenScreenTags(ns,tag...) (struct Screen *)RT_Add(RTT_SCREEN,RTTO_OpenScreenTags,(ns),##tag)
194 # undef CloseScreen
195 # define CloseScreen(s) (void)RT_Free(RTT_SCREEN,(s))
196 # undef ScreenToFront
197 # define ScreenToFront(s) (void)RT_Check(RTT_SCREEN,RTTO_ScreenToFront,(s))
198 # undef ScreenToBack
199 # define ScreenToBack(s) (void)RT_Check(RTT_SCREEN,RTTO_ScreenToBack,(s))
201 # undef OpenWindow
202 # define OpenWindow(nw) (struct Window *)RT_Add(RTT_WINDOW,RTTO_OpenWindow,(nw))
203 # undef OpenWindowTagList
204 # define OpenWindowTagList(nw,tl) (struct Window *)RT_Add(RTT_WINDOW,RTTO_OpenWindowTagList,(nw),(tl))
205 # undef OpenWindowTags
206 # define OpenWindowTags(nw,tag...) (struct Window *)RT_Add(RTT_WINDOW,RTTO_OpenWindowTags,(nw),##tag)
207 # undef CloseWindow
208 # define CloseWindow(w) (void)RT_Free(RTT_WINDOW,(w))
209 # undef WindowToFront
210 # define WindowToFront(w) (void)RT_Check(RTT_WINDOW,RTTO_WindowToFront,(w))
211 # undef WindowToBack
212 # define WindowToBack(w) (void)RT_Check(RTT_WINDOW,RTTO_WindowToBack,(w))
213 # else
214 # define RT_INITINTUITION
215 # define RT_EXITINTUITION
216 # endif /* ENABLE_RT_INTUITION */
217 # endif /* ENABLE_RT */
219 # undef RT_Init
220 # define RT_Init() \
221 RT_IntInitB(), \
222 RT_INITEXEC \
223 RT_INITDOS \
224 RT_INITINTUITION \
225 RT_IntInitE()
227 # undef RT_Exit
228 # define RT_Exit() \
229 RT_IntExitB(), \
230 RT_EXITINTUITION \
231 RT_EXITDOS \
232 RT_EXITEXEC \
233 RT_IntExitE()
235 #else /* ENABLE_RT || defined(RT_INTERNAL) */
236 # ifndef RT_Init
237 # define RT_Init() /* eps */
238 # define RT_Exit() /* eps */
239 # define RT_Add(rtt, args...) /* eps */
240 # define RT_Check(rtt, args...) /* eps */
241 # define RT_Free(rtt, args...) /* eps */
242 # define RT_Enter() /* eps */
243 # define RT_Leave() /* eps */
244 # endif
245 #endif /* ENABLE_RT || defined(RT_INTERNAL) */