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