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