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

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

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