[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.4

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

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