[BACK]Return to gc_risa.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Diff for /OpenXM_contrib2/asir2000/parse/gc_risa.c between version 1.7 and 1.20

version 1.7, 2009/02/06 08:58:28 version 1.20, 2018/06/09 06:34:17
Line 1 
Line 1 
 /* $OpenXM: OpenXM_contrib2/asir2000/parse/gc_risa.c,v 1.6 2009/02/05 11:25:59 ohara Exp $ */  /* $OpenXM: OpenXM_contrib2/asir2000/parse/gc_risa.c,v 1.19 2018/03/29 01:32:54 noro Exp $ */
   
   #if defined(VISUAL) || defined(__MINGW32__)
   #include "private/gcconfig.h"
   #if !defined(SIGUSR1)
   #define SIGUSR1 30
   #endif
   #endif
 #include "gc.h"  #include "gc.h"
 #include <time.h>  #include <time.h>
   #include <signal.h>
   
 void error(char *);  void error(char *);
   void int_handler();
   
 int *StackBottom;  int *StackBottom;
   int in_gc, caught_intr;
   
   void check_caught_intr()
   {
     if ( caught_intr == 1 ) {
       caught_intr = 0;
       int_handler(SIGINT);
     } else if ( caught_intr == 2 ) {
       caught_intr = 0;
       ox_usr1_handler(SIGUSR1);
       }
   }
   
 void *Risa_GC_malloc(size_t d)  void *Risa_GC_malloc(size_t d)
 {  {
         void *ret;    void *ret;
   
         ret = (void *)GC_malloc(d);    in_gc = 1;
         if ( !ret )    ret = (void *)GC_malloc(d);
                 error("GC_malloc : failed to allocate memory");    in_gc = 0;
         return ret;    check_caught_intr();
     if ( !ret )
       error("GC_malloc : failed to allocate memory");
     return ret;
 }  }
   
 void *Risa_GC_malloc_atomic(size_t d)  void *Risa_GC_malloc_atomic(size_t d)
 {  {
         void *ret;    void *ret;
   
         ret = (void *)GC_malloc_atomic(d);    in_gc = 1;
         if ( !ret )    ret = (void *)GC_malloc_atomic(d);
                 error("GC_malloc_atomic : failed to allocate memory");    in_gc = 0;
         return ret;    check_caught_intr();
     if ( !ret )
       error("GC_malloc_atomic : failed to allocate memory");
     return ret;
 }  }
   
   void *Risa_GC_malloc_atomic_ignore_off_page(size_t d)
   {
     void *ret;
   
     in_gc = 1;
     ret = (void *)GC_malloc_atomic_ignore_off_page(d);
     in_gc = 0;
     check_caught_intr();
     if ( !ret )
       error("GC_malloc_atomic_ignore_off_page : failed to allocate memory");
     return ret;
   }
   
 void *Risa_GC_realloc(void *p,size_t d)  void *Risa_GC_realloc(void *p,size_t d)
 {  {
         void *ret;    void *ret;
   
         ret = (void *)GC_realloc(p,d);    in_gc = 1;
         if ( !ret )    ret = (void *)GC_realloc(p,d);
                 error("GC_realloc : failed to reallocate memory");    in_gc = 0;
         return ret;    check_caught_intr();
     if ( !ret )
       error("GC_realloc : failed to reallocate memory");
     return ret;
 }  }
   
 int get_heapsize()  void Risa_GC_free(void *p)
 {  {
         return GC_get_heap_size();    in_gc = 1;
     GC_free(p);
     in_gc = 0;
     check_caught_intr();
 }  }
   
   size_t get_heapsize()
   {
     return GC_get_heap_size();
   }
   
 #if !defined(BYTES_TO_WORDS)  #if !defined(BYTES_TO_WORDS)
 #define BYTES_TO_WORDS(x)   ((x)>>2)  #define BYTES_TO_WORDS(x)   ((x)>>2)
 #endif  #endif
   
 long get_allocwords()  size_t get_allocwords()
 {  {
         size_t n = GC_get_total_bytes();    size_t n = GC_get_total_bytes();
         return (long)BYTES_TO_WORDS(n); /* bytes to words */    return BYTES_TO_WORDS(n); /* bytes to words */
 }  }
   
 static double asir_start_time;  static double asir_start_time;
Line 59  double get_clock(), get_rtime(), get_current_time();
Line 109  double get_clock(), get_rtime(), get_current_time();
 void rtime_init()  void rtime_init()
 {  {
 #if defined(i386) && defined(linux)  #if defined(i386) && defined(linux)
         unsigned short cw;    unsigned short cw;
   
 #define fldcw(addr)             __asm("fldcw %0" : : "m" (*addr))  #define fldcw(addr)             __asm("fldcw %0" : : "m" (*addr))
 #define fnstcw(addr)            __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr))  #define fnstcw(addr)            __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr))
         fnstcw(&cw); cw &= 0xfeff; cw |= 0x0200; fldcw(&cw);    fnstcw(&cw); cw &= 0xfeff; cw |= 0x0200; fldcw(&cw);
 #endif  #endif
         asir_start_time = get_current_time();    asir_start_time = get_current_time();
 }  }
   
 double get_rtime()  double get_rtime()
 {  {
         return get_current_time() - asir_start_time;    return get_current_time() - asir_start_time;
 }  }
   
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__)
 #include <windows.h>  #include <windows.h>
   
 extern int recv_intr,doing_batch;  extern int recv_intr,doing_batch;
Line 81  void send_intr();
Line 131  void send_intr();
   
 BOOL set_ctrlc_flag(DWORD type)  BOOL set_ctrlc_flag(DWORD type)
 {  {
         if ( doing_batch )    enter_signal_cs();
                 send_intr();    if ( doing_batch ) {
         else      send_intr();
                 recv_intr = 1;    }else {
         return TRUE;      recv_intr = 1;
     }
     leave_signal_cs();
     return TRUE;
 }  }
   
 void register_ctrlc_handler() {  void register_ctrlc_handler() {
         SetConsoleCtrlHandler((PHANDLER_ROUTINE)set_ctrlc_flag,TRUE);    SetConsoleCtrlHandler((PHANDLER_ROUTINE)set_ctrlc_flag,TRUE);
 }  }
   
 int mythreadid() {  int mythreadid() {
         return GetCurrentThreadId();    return GetCurrentThreadId();
 }  }
   
 double get_current_time()  double get_current_time()
 {  {
 //      return (double)clock()/(double)CLOCKS_PER_SEC;  //  return (double)clock()/(double)CLOCKS_PER_SEC;
         return ((double)GetTickCount())/1000.0;    return ((double)GetTickCount())/1000.0;
 }  }
   
 double get_clock()  double get_clock()
 {  {
         static int initialized = 0;    static int initialized = 0;
         static int is_winnt = 0;    static int is_winnt = 0;
         static HANDLE curproc;    static HANDLE curproc;
   
         if ( !initialized ) {    if ( !initialized ) {
                 OSVERSIONINFO vinfo;      OSVERSIONINFO vinfo;
   
                 curproc = GetCurrentProcess();      curproc = GetCurrentProcess();
                 vinfo.dwOSVersionInfoSize = sizeof(vinfo);      vinfo.dwOSVersionInfoSize = sizeof(vinfo);
                 GetVersionEx(&vinfo);      GetVersionEx(&vinfo);
                 if ( vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT )      if ( vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
                         is_winnt = 1;        is_winnt = 1;
                 else      else
                         is_winnt = 0;        is_winnt = 0;
         }    }
         if ( is_winnt ) {    if ( is_winnt ) {
                 FILETIME c,e,k,u;      FILETIME c,e,k,u;
   
                 GetProcessTimes(curproc,&c,&e,&k,&u);      GetProcessTimes(curproc,&c,&e,&k,&u);
                 return ((double)k.dwLowDateTime+(double)u.dwLowDateTime      return ((double)k.dwLowDateTime+(double)u.dwLowDateTime
                         +4294967296.0*((double)k.dwHighDateTime+(double)u.dwHighDateTime))/10000000.0;        +4294967296.0*((double)k.dwHighDateTime+(double)u.dwHighDateTime))/10000000.0;
         } else    } else
                 return get_current_time();      return get_current_time();
 }  }
 #elif defined(THINK_C) || defined(__MWERKS__) || defined(MSWIN32)  #elif defined(THINK_C) || defined(__MWERKS__) || defined(MSWIN32)
 double get_current_time()  double get_current_time()
 {  {
         return get_clock();    return get_clock();
 }  }
   
 double get_clock()  double get_clock()
 {  {
         clock_t c;    clock_t c;
   
         c = clock();    c = clock();
         return (double)c/(double)CLOCKS_PER_SEC;    return (double)c/(double)CLOCKS_PER_SEC;
 }  }
 #else  #else
 #include <sys/time.h>  #include <sys/time.h>
   
 double get_current_time()  double get_current_time()
 {  {
         struct timeval t;    struct timeval t;
         struct timezone z;    struct timezone z;
   
         gettimeofday(&t,&z);    gettimeofday(&t,&z);
         return (double)t.tv_sec + ((double)t.tv_usec)/((double)1000000);    return (double)t.tv_sec + ((double)t.tv_usec)/((double)1000000);
 }  }
   
 #if defined(_PA_RISC1_1) || defined(__svr4__) || defined(__CYGWIN__)  #if defined(_PA_RISC1_1) || defined(__svr4__) || defined(__CYGWIN__)
Line 160  double get_current_time()
Line 213  double get_current_time()
   
 double get_clock()  double get_clock()
 {  {
         struct tms buf;    struct tms buf;
   
         times(&buf);    times(&buf);
         return (double)(buf.tms_utime+buf.tms_stime)/(double)CLK_TCK;    return (double)(buf.tms_utime+buf.tms_stime)/(double)CLK_TCK;
 }  }
 #else  #else
   
Line 171  double get_clock()
Line 224  double get_clock()
   
 double get_clock()  double get_clock()
 {  {
         int tv_sec,tv_usec;    int tv_sec,tv_usec;
         struct rusage ru;    struct rusage ru;
   
         getrusage(RUSAGE_SELF,&ru);    getrusage(RUSAGE_SELF,&ru);
         tv_sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;    tv_sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
         tv_usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;    tv_usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
         return (double)tv_sec+(double)tv_usec/(double)1000000;    return (double)tv_sec+(double)tv_usec/(double)1000000;
 }  }
 #endif  #endif
 #endif  #endif
   
 #if 1  #if !defined(NO_ASIR_GC)
 extern int GC_free_space_numerator;  extern int GC_free_space_numerator;
   
 void Risa_GC_get_adj(int *nm, int *dn) {  void Risa_GC_get_adj(int *nm, int *dn) {
         *nm = GC_free_space_numerator;    *nm = GC_free_space_numerator;
         *dn = GC_free_space_divisor;    *dn = GC_free_space_divisor;
 }  }
   
 void Risa_GC_set_adj(int nm, int dn) {  void Risa_GC_set_adj(int nm, int dn) {
         GC_free_space_numerator = nm;    GC_free_space_numerator = nm;
         GC_free_space_divisor = dn;    GC_free_space_divisor = dn;
 }  }
 #else  #else
 void Risa_GC_get_adj(int *nm, int *dn) {  void Risa_GC_get_adj(int *nm, int *dn) {
         *nm = 1;    *nm = 1;
         *dn = GC_free_space_divisor;    *dn = GC_free_space_divisor;
 }  }
   
 void Risa_GC_set_adj(int nm, int dn) {  void Risa_GC_set_adj(int nm, int dn) {
         GC_free_space_divisor = dn/nm;    GC_free_space_divisor = dn/nm;
 }  }
   
 double GC_get_gctime() {  double GC_get_gctime() {
         return 0.0;    return 0.0;
 }  }
 #endif  #endif
   
 #if defined(MSWIN32) && !defined(VISUAL)  #if defined(MSWIN32) && !defined(VISUAL) && !defined(__MINGW32__)
 #include <signal.h>  #include <signal.h>
 void process_events() {  void process_events() {
         if ( check_break() )    if ( check_break() )
                 raise(SIGINT);      raise(SIGINT);
 }  }
 #endif  #endif
   
Line 225  int sigsetmask(int mask){ return 0; }
Line 278  int sigsetmask(int mask){ return 0; }
   
 void process_events() {  void process_events() {
   
         register EvQElPtr q;    register EvQElPtr q;
 #if 0  #if 0
         extern void (*app_process_events)();    extern void (*app_process_events)();
 #endif  #endif
   
         for (q = (EvQElPtr) GetEventQueue()->qHead; q; q = (EvQElPtr) q->qLink)    for (q = (EvQElPtr) GetEventQueue()->qHead; q; q = (EvQElPtr) q->qLink)
                 if (q->evtQWhat == keyDown && (char) q->evtQMessage == '.')      if (q->evtQWhat == keyDown && (char) q->evtQMessage == '.')
                         if (q->evtQModifiers & cmdKey) {        if (q->evtQModifiers & cmdKey) {
                                 raise(SIGINT); break;          raise(SIGINT); break;
                         }        }
 #if 0  #if 0
         if ( app_process_events )    if ( app_process_events )
                 (*app_process_events)();      (*app_process_events)();
 #endif  #endif
 }  }
 #endif  #endif
   
 #if defined(VISUAL) && !defined(MSWIN32)  #if (defined(VISUAL) || defined(__MINGW32__)) && !defined(MSWIN32)
 int sigsetmask(mask) int mask; { return 0; }  int sigsetmask(mask) int mask; { return 0; }
   
 void process_events() {  void process_events() {
 int c;  int c;
   
         while ( c = read_cons() )    while ( c = read_cons() )
 #if defined(GO32)  #if defined(GO32)
                 if ( c == ('x' & 037 ) )      if ( c == ('x' & 037 ) )
 #else  #else
                 if ( c == ('c' & 037 ) )      if ( c == ('c' & 037 ) )
 #endif  #endif
                         int_handler();        int_handler(SIGINT);
 }  }
 #endif  #endif

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.20

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