Annotation of OpenXM_contrib2/asir2000/parse/gc_risa.c, Revision 1.9
1.9 ! ohara 1: /* $OpenXM: OpenXM_contrib2/asir2000/parse/gc_risa.c,v 1.8 2009/02/06 10:11:12 ohara 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;
12:
13: void *Risa_GC_malloc(size_t d)
14: {
15: void *ret;
16:
17: ret = (void *)GC_malloc(d);
18: if ( !ret )
19: error("GC_malloc : failed to allocate memory");
20: return ret;
21: }
22:
23: void *Risa_GC_malloc_atomic(size_t d)
24: {
25: void *ret;
26:
27: ret = (void *)GC_malloc_atomic(d);
28: if ( !ret )
29: error("GC_malloc_atomic : failed to allocate memory");
30: return ret;
31: }
32:
33: void *Risa_GC_realloc(void *p,size_t d)
34: {
35: void *ret;
36:
37: ret = (void *)GC_realloc(p,d);
38: if ( !ret )
39: error("GC_realloc : failed to reallocate memory");
40: return ret;
41: }
42:
43: int get_heapsize()
44: {
1.5 ohara 45: return GC_get_heap_size();
1.1 noro 46: }
47:
1.5 ohara 48: #if !defined(BYTES_TO_WORDS)
49: #define BYTES_TO_WORDS(x) ((x)>>2)
50: #endif
51:
1.2 noro 52: long get_allocwords()
1.1 noro 53: {
1.5 ohara 54: size_t n = GC_get_total_bytes();
55: return (long)BYTES_TO_WORDS(n); /* bytes to words */
1.1 noro 56: }
57:
1.7 ohara 58: static double asir_start_time;
1.1 noro 59:
60: double get_clock(), get_rtime(), get_current_time();
61:
62: void rtime_init()
63: {
64: #if defined(i386) && defined(linux)
65: unsigned short cw;
66:
67: #define fldcw(addr) __asm("fldcw %0" : : "m" (*addr))
68: #define fnstcw(addr) __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr))
69: fnstcw(&cw); cw &= 0xfeff; cw |= 0x0200; fldcw(&cw);
70: #endif
71: asir_start_time = get_current_time();
72: }
73:
74: double get_rtime()
75: {
76: return get_current_time() - asir_start_time;
77: }
78:
79: #if defined(VISUAL)
80: #include <windows.h>
81:
82: extern int recv_intr,doing_batch;
83: void send_intr();
84:
85: BOOL set_ctrlc_flag(DWORD type)
86: {
87: if ( doing_batch )
88: send_intr();
89: else
90: recv_intr = 1;
91: return TRUE;
92: }
93:
94: void register_ctrlc_handler() {
95: SetConsoleCtrlHandler((PHANDLER_ROUTINE)set_ctrlc_flag,TRUE);
96: }
97:
98: int mythreadid() {
99: return GetCurrentThreadId();
100: }
101:
102: double get_current_time()
103: {
104: // return (double)clock()/(double)CLOCKS_PER_SEC;
105: return ((double)GetTickCount())/1000.0;
106: }
107:
108: double get_clock()
109: {
110: static int initialized = 0;
111: static int is_winnt = 0;
112: static HANDLE curproc;
113:
114: if ( !initialized ) {
115: OSVERSIONINFO vinfo;
116:
117: curproc = GetCurrentProcess();
118: vinfo.dwOSVersionInfoSize = sizeof(vinfo);
119: GetVersionEx(&vinfo);
120: if ( vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
121: is_winnt = 1;
122: else
123: is_winnt = 0;
124: }
125: if ( is_winnt ) {
126: FILETIME c,e,k,u;
127:
128: GetProcessTimes(curproc,&c,&e,&k,&u);
129: return ((double)k.dwLowDateTime+(double)u.dwLowDateTime
130: +4294967296.0*((double)k.dwHighDateTime+(double)u.dwHighDateTime))/10000000.0;
131: } else
132: return get_current_time();
133: }
1.7 ohara 134: #elif defined(THINK_C) || defined(__MWERKS__) || defined(MSWIN32)
1.1 noro 135: double get_current_time()
136: {
137: return get_clock();
138: }
139:
140: double get_clock()
141: {
142: clock_t c;
143:
144: c = clock();
145: return (double)c/(double)CLOCKS_PER_SEC;
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/resource.h>
174:
175: double get_clock()
176: {
177: int tv_sec,tv_usec;
178: struct rusage ru;
179:
180: getrusage(RUSAGE_SELF,&ru);
181: tv_sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
182: tv_usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
183: return (double)tv_sec+(double)tv_usec/(double)1000000;
184: }
185: #endif
186: #endif
187:
1.8 ohara 188: #if !defined(NO_ASIR_GC)
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: }
1.7 ohara 200: #else
201: void Risa_GC_get_adj(int *nm, int *dn) {
202: *nm = 1;
203: *dn = GC_free_space_divisor;
204: }
1.4 ohara 205:
1.7 ohara 206: void Risa_GC_set_adj(int nm, int dn) {
207: GC_free_space_divisor = dn/nm;
1.1 noro 208: }
209:
1.7 ohara 210: double GC_get_gctime() {
211: return 0.0;
1.1 noro 212: }
1.7 ohara 213: #endif
1.1 noro 214:
215: #if defined(MSWIN32) && !defined(VISUAL)
216: #include <signal.h>
217: void process_events() {
218: if ( check_break() )
219: raise(SIGINT);
220: }
221: #endif
222:
223: #if defined(THINK_C) || defined(__MWERKS__)
224: #include <signal.h>
225: #include <Events.h>
226:
227: int sigsetmask(int mask){ return 0; }
228:
229: void process_events() {
230:
231: register EvQElPtr q;
232: #if 0
233: extern void (*app_process_events)();
234: #endif
235:
236: for (q = (EvQElPtr) GetEventQueue()->qHead; q; q = (EvQElPtr) q->qLink)
237: if (q->evtQWhat == keyDown && (char) q->evtQMessage == '.')
238: if (q->evtQModifiers & cmdKey) {
239: raise(SIGINT); break;
240: }
241: #if 0
242: if ( app_process_events )
243: (*app_process_events)();
244: #endif
245: }
246: #endif
247:
248: #if defined(VISUAL) && !defined(MSWIN32)
249: int sigsetmask(mask) int mask; { return 0; }
250:
251: void process_events() {
252: int c;
253:
254: while ( c = read_cons() )
255: #if defined(GO32)
256: if ( c == ('x' & 037 ) )
257: #else
258: if ( c == ('c' & 037 ) )
259: #endif
260: int_handler();
261: }
262: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>