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

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

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