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