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