[BACK]Return to gc_risa.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/gc_risa.c, Revision 1.20

1.20    ! ohara       1: /* $OpenXM: OpenXM_contrib2/asir2000/parse/gc_risa.c,v 1.19 2018/03/29 01:32:54 noro Exp $ */
1.6       ohara       2:
1.16      fujimoto    3: #if defined(VISUAL) || defined(__MINGW32__)
1.9       ohara       4: #include "private/gcconfig.h"
1.20    ! ohara       5: #if !defined(SIGUSR1)
        !             6: #define SIGUSR1 30
        !             7: #endif
1.9       ohara       8: #endif
1.5       ohara       9: #include "gc.h"
1.1       noro       10: #include <time.h>
1.17      ohara      11: #include <signal.h>
1.1       noro       12:
                     13: void error(char *);
1.13      ohara      14: void int_handler();
1.1       noro       15:
                     16: int *StackBottom;
1.11      noro       17: int in_gc, caught_intr;
1.1       noro       18:
1.17      ohara      19: void check_caught_intr()
                     20: {
1.19      noro       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);
1.18      noro       27:     }
1.17      ohara      28: }
                     29:
1.1       noro       30: void *Risa_GC_malloc(size_t d)
                     31: {
1.19      noro       32:   void *ret;
1.1       noro       33:
1.19      noro       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;
1.1       noro       41: }
                     42:
                     43: void *Risa_GC_malloc_atomic(size_t d)
                     44: {
1.19      noro       45:   void *ret;
1.1       noro       46:
1.19      noro       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;
1.1       noro       54: }
                     55:
1.11      noro       56: void *Risa_GC_malloc_atomic_ignore_off_page(size_t d)
                     57: {
1.19      noro       58:   void *ret;
1.11      noro       59:
1.19      noro       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;
1.11      noro       67: }
                     68:
1.1       noro       69: void *Risa_GC_realloc(void *p,size_t d)
                     70: {
1.19      noro       71:   void *ret;
1.1       noro       72:
1.19      noro       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;
1.1       noro       80: }
                     81:
1.11      noro       82: void Risa_GC_free(void *p)
                     83: {
1.19      noro       84:   in_gc = 1;
                     85:   GC_free(p);
                     86:   in_gc = 0;
                     87:   check_caught_intr();
1.11      noro       88: }
                     89:
1.12      ohara      90: size_t get_heapsize()
1.1       noro       91: {
1.19      noro       92:   return GC_get_heap_size();
1.1       noro       93: }
                     94:
1.5       ohara      95: #if !defined(BYTES_TO_WORDS)
                     96: #define BYTES_TO_WORDS(x)   ((x)>>2)
                     97: #endif
                     98:
1.10      ohara      99: size_t get_allocwords()
1.1       noro      100: {
1.19      noro      101:   size_t n = GC_get_total_bytes();
                    102:   return BYTES_TO_WORDS(n); /* bytes to words */
1.1       noro      103: }
                    104:
1.7       ohara     105: static double asir_start_time;
1.1       noro      106:
                    107: double get_clock(), get_rtime(), get_current_time();
                    108:
                    109: void rtime_init()
                    110: {
                    111: #if defined(i386) && defined(linux)
1.19      noro      112:   unsigned short cw;
1.1       noro      113:
                    114: #define fldcw(addr)             __asm("fldcw %0" : : "m" (*addr))
                    115: #define fnstcw(addr)            __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr))
1.19      noro      116:   fnstcw(&cw); cw &= 0xfeff; cw |= 0x0200; fldcw(&cw);
1.1       noro      117: #endif
1.19      noro      118:   asir_start_time = get_current_time();
1.1       noro      119: }
                    120:
                    121: double get_rtime()
                    122: {
1.19      noro      123:   return get_current_time() - asir_start_time;
1.1       noro      124: }
                    125:
1.16      fujimoto  126: #if defined(VISUAL) || defined(__MINGW32__)
1.1       noro      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: {
1.19      noro      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;
1.1       noro      142: }
                    143:
                    144: void register_ctrlc_handler() {
1.19      noro      145:   SetConsoleCtrlHandler((PHANDLER_ROUTINE)set_ctrlc_flag,TRUE);
1.1       noro      146: }
                    147:
                    148: int mythreadid() {
1.19      noro      149:   return GetCurrentThreadId();
1.1       noro      150: }
                    151:
                    152: double get_current_time()
                    153: {
1.19      noro      154: //  return (double)clock()/(double)CLOCKS_PER_SEC;
                    155:   return ((double)GetTickCount())/1000.0;
1.1       noro      156: }
                    157:
                    158: double get_clock()
                    159: {
1.19      noro      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();
1.1       noro      183: }
1.7       ohara     184: #elif defined(THINK_C) || defined(__MWERKS__) || defined(MSWIN32)
1.1       noro      185: double get_current_time()
                    186: {
1.19      noro      187:   return get_clock();
1.1       noro      188: }
                    189:
                    190: double get_clock()
                    191: {
1.19      noro      192:   clock_t c;
1.1       noro      193:
1.19      noro      194:   c = clock();
                    195:   return (double)c/(double)CLOCKS_PER_SEC;
1.1       noro      196: }
                    197: #else
                    198: #include <sys/time.h>
                    199:
                    200: double get_current_time()
                    201: {
1.19      noro      202:   struct timeval t;
                    203:   struct timezone z;
1.1       noro      204:
1.19      noro      205:   gettimeofday(&t,&z);
                    206:   return (double)t.tv_sec + ((double)t.tv_usec)/((double)1000000);
1.1       noro      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: {
1.19      noro      216:   struct tms buf;
1.1       noro      217:
1.19      noro      218:   times(&buf);
                    219:   return (double)(buf.tms_utime+buf.tms_stime)/(double)CLK_TCK;
1.1       noro      220: }
                    221: #else
                    222:
                    223: #include <sys/resource.h>
                    224:
                    225: double get_clock()
                    226: {
1.19      noro      227:   int tv_sec,tv_usec;
                    228:   struct rusage ru;
1.1       noro      229:
1.19      noro      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;
1.1       noro      234: }
                    235: #endif
                    236: #endif
                    237:
1.8       ohara     238: #if !defined(NO_ASIR_GC)
1.4       ohara     239: extern int GC_free_space_numerator;
                    240:
                    241: void Risa_GC_get_adj(int *nm, int *dn) {
1.19      noro      242:   *nm = GC_free_space_numerator;
                    243:   *dn = GC_free_space_divisor;
1.4       ohara     244: }
                    245:
                    246: void Risa_GC_set_adj(int nm, int dn) {
1.19      noro      247:   GC_free_space_numerator = nm;
                    248:   GC_free_space_divisor = dn;
1.4       ohara     249: }
1.7       ohara     250: #else
                    251: void Risa_GC_get_adj(int *nm, int *dn) {
1.19      noro      252:   *nm = 1;
                    253:   *dn = GC_free_space_divisor;
1.7       ohara     254: }
1.4       ohara     255:
1.7       ohara     256: void Risa_GC_set_adj(int nm, int dn) {
1.19      noro      257:   GC_free_space_divisor = dn/nm;
1.1       noro      258: }
                    259:
1.7       ohara     260: double GC_get_gctime() {
1.19      noro      261:   return 0.0;
1.1       noro      262: }
1.7       ohara     263: #endif
1.1       noro      264:
1.16      fujimoto  265: #if defined(MSWIN32) && !defined(VISUAL) && !defined(__MINGW32__)
1.1       noro      266: #include <signal.h>
                    267: void process_events() {
1.19      noro      268:   if ( check_break() )
                    269:     raise(SIGINT);
1.1       noro      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:
1.19      noro      281:   register EvQElPtr q;
1.1       noro      282: #if 0
1.19      noro      283:   extern void (*app_process_events)();
1.1       noro      284: #endif
                    285:
1.19      noro      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:       }
1.1       noro      291: #if 0
1.19      noro      292:   if ( app_process_events )
                    293:     (*app_process_events)();
1.1       noro      294: #endif
                    295: }
                    296: #endif
                    297:
1.16      fujimoto  298: #if (defined(VISUAL) || defined(__MINGW32__)) && !defined(MSWIN32)
1.1       noro      299: int sigsetmask(mask) int mask; { return 0; }
                    300:
                    301: void process_events() {
                    302: int c;
                    303:
1.19      noro      304:   while ( c = read_cons() )
1.1       noro      305: #if defined(GO32)
1.19      noro      306:     if ( c == ('x' & 037 ) )
1.1       noro      307: #else
1.19      noro      308:     if ( c == ('c' & 037 ) )
1.1       noro      309: #endif
1.19      noro      310:       int_handler(SIGINT);
1.1       noro      311: }
                    312: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>