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

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

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