Annotation of OpenXM_contrib2/asir2000/parse/gc_risa.c, Revision 1.18
1.18 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/parse/gc_risa.c,v 1.17 2017/08/30 09:40:30 ohara 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.18 ! noro 18: if ( caught_intr == 1 ) {
1.17 ohara 19: caught_intr = 0;
20: int_handler(SIGINT);
1.18 ! noro 21: } else if ( caught_intr == 2 ) {
! 22: caught_intr = 0;
! 23: ox_usr1_handler(SIGUSR1);
! 24: }
1.17 ohara 25: }
26:
1.1 noro 27: void *Risa_GC_malloc(size_t d)
28: {
29: void *ret;
30:
1.11 noro 31: in_gc = 1;
1.1 noro 32: ret = (void *)GC_malloc(d);
1.11 noro 33: in_gc = 0;
1.17 ohara 34: check_caught_intr();
1.1 noro 35: if ( !ret )
36: error("GC_malloc : failed to allocate memory");
37: return ret;
38: }
39:
40: void *Risa_GC_malloc_atomic(size_t d)
41: {
42: void *ret;
43:
1.11 noro 44: in_gc = 1;
1.1 noro 45: ret = (void *)GC_malloc_atomic(d);
1.11 noro 46: in_gc = 0;
1.17 ohara 47: check_caught_intr();
1.1 noro 48: if ( !ret )
49: error("GC_malloc_atomic : failed to allocate memory");
50: return ret;
51: }
52:
1.11 noro 53: void *Risa_GC_malloc_atomic_ignore_off_page(size_t d)
54: {
55: void *ret;
56:
57: in_gc = 1;
58: ret = (void *)GC_malloc_atomic_ignore_off_page(d);
59: in_gc = 0;
1.17 ohara 60: check_caught_intr();
1.11 noro 61: if ( !ret )
62: error("GC_malloc_atomic_ignore_off_page : failed to allocate memory");
63: return ret;
64: }
65:
1.1 noro 66: void *Risa_GC_realloc(void *p,size_t d)
67: {
68: void *ret;
69:
1.11 noro 70: in_gc = 1;
1.1 noro 71: ret = (void *)GC_realloc(p,d);
1.11 noro 72: in_gc = 0;
1.17 ohara 73: check_caught_intr();
1.1 noro 74: if ( !ret )
75: error("GC_realloc : failed to reallocate memory");
76: return ret;
77: }
78:
1.11 noro 79: void Risa_GC_free(void *p)
80: {
81: in_gc = 1;
82: GC_free(p);
83: in_gc = 0;
1.17 ohara 84: check_caught_intr();
1.11 noro 85: }
86:
1.12 ohara 87: size_t get_heapsize()
1.1 noro 88: {
1.5 ohara 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.5 ohara 98: size_t n = GC_get_total_bytes();
1.10 ohara 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)
109: unsigned short cw;
110:
111: #define fldcw(addr) __asm("fldcw %0" : : "m" (*addr))
112: #define fnstcw(addr) __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr))
113: fnstcw(&cw); cw &= 0xfeff; cw |= 0x0200; fldcw(&cw);
114: #endif
115: asir_start_time = get_current_time();
116: }
117:
118: double get_rtime()
119: {
120: return get_current_time() - asir_start_time;
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.17 ohara 131: enter_signal_cs();
132: if ( doing_batch ) {
1.1 noro 133: send_intr();
1.17 ohara 134: }else {
1.1 noro 135: recv_intr = 1;
1.17 ohara 136: }
137: leave_signal_cs();
1.1 noro 138: return TRUE;
139: }
140:
141: void register_ctrlc_handler() {
142: SetConsoleCtrlHandler((PHANDLER_ROUTINE)set_ctrlc_flag,TRUE);
143: }
144:
145: int mythreadid() {
146: return GetCurrentThreadId();
147: }
148:
149: double get_current_time()
150: {
151: // return (double)clock()/(double)CLOCKS_PER_SEC;
152: return ((double)GetTickCount())/1000.0;
153: }
154:
155: double get_clock()
156: {
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();
180: }
1.7 ohara 181: #elif defined(THINK_C) || defined(__MWERKS__) || defined(MSWIN32)
1.1 noro 182: double get_current_time()
183: {
184: return get_clock();
185: }
186:
187: double get_clock()
188: {
189: clock_t c;
190:
191: c = clock();
192: return (double)c/(double)CLOCKS_PER_SEC;
193: }
194: #else
195: #include <sys/time.h>
196:
197: double get_current_time()
198: {
199: struct timeval t;
200: struct timezone z;
201:
202: gettimeofday(&t,&z);
203: return (double)t.tv_sec + ((double)t.tv_usec)/((double)1000000);
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: {
213: struct tms buf;
214:
215: times(&buf);
216: return (double)(buf.tms_utime+buf.tms_stime)/(double)CLK_TCK;
217: }
218: #else
219:
220: #include <sys/resource.h>
221:
222: double get_clock()
223: {
224: int tv_sec,tv_usec;
225: struct rusage ru;
226:
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;
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) {
239: *nm = GC_free_space_numerator;
240: *dn = GC_free_space_divisor;
241: }
242:
243: void Risa_GC_set_adj(int nm, int dn) {
244: GC_free_space_numerator = nm;
245: GC_free_space_divisor = dn;
246: }
1.7 ohara 247: #else
248: void Risa_GC_get_adj(int *nm, int *dn) {
249: *nm = 1;
250: *dn = GC_free_space_divisor;
251: }
1.4 ohara 252:
1.7 ohara 253: void Risa_GC_set_adj(int nm, int dn) {
254: GC_free_space_divisor = dn/nm;
1.1 noro 255: }
256:
1.7 ohara 257: double GC_get_gctime() {
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() {
265: if ( check_break() )
266: raise(SIGINT);
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:
278: register EvQElPtr q;
279: #if 0
280: extern void (*app_process_events)();
281: #endif
282:
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: }
288: #if 0
289: if ( app_process_events )
290: (*app_process_events)();
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:
301: while ( c = read_cons() )
302: #if defined(GO32)
303: if ( c == ('x' & 037 ) )
304: #else
305: if ( c == ('c' & 037 ) )
306: #endif
1.17 ohara 307: int_handler(SIGINT);
1.1 noro 308: }
309: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>