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