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