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