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

Annotation of OpenXM_contrib2/asir2018/parse/gc_risa.c, Revision 1.6

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

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