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

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

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