Annotation of OpenXM_contrib2/asir2000/parse/gc_risa.c, Revision 1.12
1.12 ! ohara 1: /* $OpenXM: OpenXM_contrib2/asir2000/parse/gc_risa.c,v 1.11 2012/12/17 07:20:45 noro Exp $ */
1.6 ohara 2:
1.9 ohara 3: #if defined(VISUAL)
4: #include "private/gcconfig.h"
5: #endif
1.5 ohara 6: #include "gc.h"
1.1 noro 7: #include <time.h>
8:
9: void error(char *);
10:
11: int *StackBottom;
1.11 noro 12: int in_gc, caught_intr;
1.1 noro 13:
14: void *Risa_GC_malloc(size_t d)
15: {
16: void *ret;
17:
1.11 noro 18: in_gc = 1;
1.1 noro 19: ret = (void *)GC_malloc(d);
1.11 noro 20: in_gc = 0;
21: if ( caught_intr ) { caught_intr = 0; int_handler(); }
1.1 noro 22: if ( !ret )
23: error("GC_malloc : failed to allocate memory");
24: return ret;
25: }
26:
27: void *Risa_GC_malloc_atomic(size_t d)
28: {
29: void *ret;
30:
1.11 noro 31: in_gc = 1;
1.1 noro 32: ret = (void *)GC_malloc_atomic(d);
1.11 noro 33: in_gc = 0;
34: if ( caught_intr ) { caught_intr = 0; int_handler(); }
1.1 noro 35: if ( !ret )
36: error("GC_malloc_atomic : failed to allocate memory");
37: return ret;
38: }
39:
1.11 noro 40: void *Risa_GC_malloc_atomic_ignore_off_page(size_t d)
41: {
42: void *ret;
43:
44: in_gc = 1;
45: ret = (void *)GC_malloc_atomic_ignore_off_page(d);
46: in_gc = 0;
47: if ( caught_intr ) { caught_intr = 0; int_handler(); }
48: if ( !ret )
49: error("GC_malloc_atomic_ignore_off_page : failed to allocate memory");
50: return ret;
51: }
52:
1.1 noro 53: void *Risa_GC_realloc(void *p,size_t d)
54: {
55: void *ret;
56:
1.11 noro 57: in_gc = 1;
1.1 noro 58: ret = (void *)GC_realloc(p,d);
1.11 noro 59: in_gc = 0;
60: if ( caught_intr ) { caught_intr = 0; int_handler(); }
1.1 noro 61: if ( !ret )
62: error("GC_realloc : failed to reallocate memory");
63: return ret;
64: }
65:
1.11 noro 66: void Risa_GC_free(void *p)
67: {
68: in_gc = 1;
69: GC_free(p);
70: in_gc = 0;
71: if ( caught_intr ) { caught_intr = 0; int_handler(); }
72: }
73:
1.12 ! ohara 74: size_t get_heapsize()
1.1 noro 75: {
1.5 ohara 76: return GC_get_heap_size();
1.1 noro 77: }
78:
1.5 ohara 79: #if !defined(BYTES_TO_WORDS)
80: #define BYTES_TO_WORDS(x) ((x)>>2)
81: #endif
82:
1.10 ohara 83: size_t get_allocwords()
1.1 noro 84: {
1.5 ohara 85: size_t n = GC_get_total_bytes();
1.10 ohara 86: return BYTES_TO_WORDS(n); /* bytes to words */
1.1 noro 87: }
88:
1.7 ohara 89: static double asir_start_time;
1.1 noro 90:
91: double get_clock(), get_rtime(), get_current_time();
92:
93: void rtime_init()
94: {
95: #if defined(i386) && defined(linux)
96: unsigned short cw;
97:
98: #define fldcw(addr) __asm("fldcw %0" : : "m" (*addr))
99: #define fnstcw(addr) __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr))
100: fnstcw(&cw); cw &= 0xfeff; cw |= 0x0200; fldcw(&cw);
101: #endif
102: asir_start_time = get_current_time();
103: }
104:
105: double get_rtime()
106: {
107: return get_current_time() - asir_start_time;
108: }
109:
110: #if defined(VISUAL)
111: #include <windows.h>
112:
113: extern int recv_intr,doing_batch;
114: void send_intr();
115:
116: BOOL set_ctrlc_flag(DWORD type)
117: {
118: if ( doing_batch )
119: send_intr();
120: else
121: recv_intr = 1;
122: return TRUE;
123: }
124:
125: void register_ctrlc_handler() {
126: SetConsoleCtrlHandler((PHANDLER_ROUTINE)set_ctrlc_flag,TRUE);
127: }
128:
129: int mythreadid() {
130: return GetCurrentThreadId();
131: }
132:
133: double get_current_time()
134: {
135: // return (double)clock()/(double)CLOCKS_PER_SEC;
136: return ((double)GetTickCount())/1000.0;
137: }
138:
139: double get_clock()
140: {
141: static int initialized = 0;
142: static int is_winnt = 0;
143: static HANDLE curproc;
144:
145: if ( !initialized ) {
146: OSVERSIONINFO vinfo;
147:
148: curproc = GetCurrentProcess();
149: vinfo.dwOSVersionInfoSize = sizeof(vinfo);
150: GetVersionEx(&vinfo);
151: if ( vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
152: is_winnt = 1;
153: else
154: is_winnt = 0;
155: }
156: if ( is_winnt ) {
157: FILETIME c,e,k,u;
158:
159: GetProcessTimes(curproc,&c,&e,&k,&u);
160: return ((double)k.dwLowDateTime+(double)u.dwLowDateTime
161: +4294967296.0*((double)k.dwHighDateTime+(double)u.dwHighDateTime))/10000000.0;
162: } else
163: return get_current_time();
164: }
1.7 ohara 165: #elif defined(THINK_C) || defined(__MWERKS__) || defined(MSWIN32)
1.1 noro 166: double get_current_time()
167: {
168: return get_clock();
169: }
170:
171: double get_clock()
172: {
173: clock_t c;
174:
175: c = clock();
176: return (double)c/(double)CLOCKS_PER_SEC;
177: }
178: #else
179: #include <sys/time.h>
180:
181: double get_current_time()
182: {
183: struct timeval t;
184: struct timezone z;
185:
186: gettimeofday(&t,&z);
187: return (double)t.tv_sec + ((double)t.tv_usec)/((double)1000000);
188: }
189:
190: #if defined(_PA_RISC1_1) || defined(__svr4__) || defined(__CYGWIN__)
191:
192: #include <sys/times.h>
193: #include <limits.h>
194:
195: double get_clock()
196: {
197: struct tms buf;
198:
199: times(&buf);
200: return (double)(buf.tms_utime+buf.tms_stime)/(double)CLK_TCK;
201: }
202: #else
203:
204: #include <sys/resource.h>
205:
206: double get_clock()
207: {
208: int tv_sec,tv_usec;
209: struct rusage ru;
210:
211: getrusage(RUSAGE_SELF,&ru);
212: tv_sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
213: tv_usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
214: return (double)tv_sec+(double)tv_usec/(double)1000000;
215: }
216: #endif
217: #endif
218:
1.8 ohara 219: #if !defined(NO_ASIR_GC)
1.4 ohara 220: extern int GC_free_space_numerator;
221:
222: void Risa_GC_get_adj(int *nm, int *dn) {
223: *nm = GC_free_space_numerator;
224: *dn = GC_free_space_divisor;
225: }
226:
227: void Risa_GC_set_adj(int nm, int dn) {
228: GC_free_space_numerator = nm;
229: GC_free_space_divisor = dn;
230: }
1.7 ohara 231: #else
232: void Risa_GC_get_adj(int *nm, int *dn) {
233: *nm = 1;
234: *dn = GC_free_space_divisor;
235: }
1.4 ohara 236:
1.7 ohara 237: void Risa_GC_set_adj(int nm, int dn) {
238: GC_free_space_divisor = dn/nm;
1.1 noro 239: }
240:
1.7 ohara 241: double GC_get_gctime() {
242: return 0.0;
1.1 noro 243: }
1.7 ohara 244: #endif
1.1 noro 245:
246: #if defined(MSWIN32) && !defined(VISUAL)
247: #include <signal.h>
248: void process_events() {
249: if ( check_break() )
250: raise(SIGINT);
251: }
252: #endif
253:
254: #if defined(THINK_C) || defined(__MWERKS__)
255: #include <signal.h>
256: #include <Events.h>
257:
258: int sigsetmask(int mask){ return 0; }
259:
260: void process_events() {
261:
262: register EvQElPtr q;
263: #if 0
264: extern void (*app_process_events)();
265: #endif
266:
267: for (q = (EvQElPtr) GetEventQueue()->qHead; q; q = (EvQElPtr) q->qLink)
268: if (q->evtQWhat == keyDown && (char) q->evtQMessage == '.')
269: if (q->evtQModifiers & cmdKey) {
270: raise(SIGINT); break;
271: }
272: #if 0
273: if ( app_process_events )
274: (*app_process_events)();
275: #endif
276: }
277: #endif
278:
279: #if defined(VISUAL) && !defined(MSWIN32)
280: int sigsetmask(mask) int mask; { return 0; }
281:
282: void process_events() {
283: int c;
284:
285: while ( c = read_cons() )
286: #if defined(GO32)
287: if ( c == ('x' & 037 ) )
288: #else
289: if ( c == ('c' & 037 ) )
290: #endif
291: int_handler();
292: }
293: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>