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

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

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