File: [local] / OpenXM_contrib2 / asir2000 / gc5.3 / Attic / gc_risa.c (download)
Revision 1.3, Tue Dec 25 02:39:03 2001 UTC (22 years, 8 months ago) by noro
Branch: MAIN
CVS Tags: RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, KNOPPIX_2006, DEB_REL_1_2_3-9 Changes since 1.2: +1 -1
lines
Modifications to support cygwin.
|
#include "gc_priv.h"
#include <time.h>
void error(char *);
int *StackBottom;
void *Risa_GC_malloc(size_t d)
{
void *ret;
ret = GC_malloc(d);
if ( !ret )
error("GC_malloc : failed to allocate memory");
return ret;
}
void *Risa_GC_malloc_atomic(size_t d)
{
void *ret;
ret = GC_malloc_atomic(d);
if ( !ret )
error("GC_malloc_atomic : failed to allocate memory");
return ret;
}
void *Risa_GC_realloc(void *p,size_t d)
{
void *ret;
ret = GC_realloc(p,d);
if ( !ret )
error("GC_realloc : failed to reallocate memory");
return ret;
}
int get_heapsize()
{
return GC_heapsize;
}
int get_allocwords()
{
return GC_words_allocd_before_gc;
}
double gctime;
static double gcstart,asir_start_time;
double get_clock(), get_rtime(), get_current_time();
void rtime_init()
{
#if defined(i386) && defined(linux)
unsigned short cw;
#define fldcw(addr) __asm("fldcw %0" : : "m" (*addr))
#define fnstcw(addr) __asm("fnstcw %0" : "=m" (*addr) : "0" (*addr))
fnstcw(&cw); cw &= 0xfeff; cw |= 0x0200; fldcw(&cw);
#endif
asir_start_time = get_current_time();
}
double get_rtime()
{
return get_current_time() - asir_start_time;
}
#if defined(THINK_C) || defined(__MWERKS__) || defined(VISUAL) || defined(MSWIN32)
#if defined(VISUAL)
#include <windows.h>
extern int recv_intr,doing_batch;
void send_intr();
BOOL set_ctrlc_flag(DWORD type)
{
if ( doing_batch )
send_intr();
else
recv_intr = 1;
return TRUE;
}
void register_ctrlc_handler() {
SetConsoleCtrlHandler((PHANDLER_ROUTINE)set_ctrlc_flag,TRUE);
}
int mythreadid() {
return GetCurrentThreadId();
}
double get_current_time()
{
// return (double)clock()/(double)CLOCKS_PER_SEC;
return ((double)GetTickCount())/1000.0;
}
double get_clock()
{
static int initialized = 0;
static int is_winnt = 0;
static HANDLE curproc;
if ( !initialized ) {
OSVERSIONINFO vinfo;
curproc = GetCurrentProcess();
vinfo.dwOSVersionInfoSize = sizeof(vinfo);
GetVersionEx(&vinfo);
if ( vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
is_winnt = 1;
else
is_winnt = 0;
}
if ( is_winnt ) {
FILETIME c,e,k,u;
GetProcessTimes(curproc,&c,&e,&k,&u);
return ((double)k.dwLowDateTime+(double)u.dwLowDateTime
+4294967296.0*((double)k.dwHighDateTime+(double)u.dwHighDateTime))/10000000.0;
} else
return get_current_time();
}
#else
double get_current_time()
{
return get_clock();
}
double get_clock()
{
clock_t c;
c = clock();
return (double)c/(double)CLOCKS_PER_SEC;
}
#endif
#else
#include <sys/time.h>
double get_current_time()
{
struct timeval t;
struct timezone z;
gettimeofday(&t,&z);
return (double)t.tv_sec + ((double)t.tv_usec)/((double)1000000);
}
#if defined(_PA_RISC1_1) || defined(__svr4__) || defined(__CYGWIN__)
#include <sys/times.h>
#include <limits.h>
double get_clock()
{
struct tms buf;
times(&buf);
return (double)(buf.tms_utime+buf.tms_stime)/(double)CLK_TCK;
}
#else
#include <sys/time.h>
#include <sys/resource.h>
double get_clock()
{
int tv_sec,tv_usec;
struct rusage ru;
getrusage(RUSAGE_SELF,&ru);
tv_sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
tv_usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
return (double)tv_sec+(double)tv_usec/(double)1000000;
}
#endif
#endif
void GC_timerstart() {
gcstart = get_clock();
}
void GC_timerstop() {
gctime += get_clock() - gcstart;
}
#if defined(MSWIN32) && !defined(VISUAL)
#include <signal.h>
void process_events() {
if ( check_break() )
raise(SIGINT);
}
#endif
#if defined(THINK_C) || defined(__MWERKS__)
#include <signal.h>
#include <Events.h>
int sigsetmask(int mask){ return 0; }
void process_events() {
register EvQElPtr q;
#if 0
extern void (*app_process_events)();
#endif
for (q = (EvQElPtr) GetEventQueue()->qHead; q; q = (EvQElPtr) q->qLink)
if (q->evtQWhat == keyDown && (char) q->evtQMessage == '.')
if (q->evtQModifiers & cmdKey) {
raise(SIGINT); break;
}
#if 0
if ( app_process_events )
(*app_process_events)();
#endif
}
#endif
#if defined(VISUAL) && !defined(MSWIN32)
int sigsetmask(mask) int mask; { return 0; }
void process_events() {
int c;
while ( c = read_cons() )
#if defined(GO32)
if ( c == ('x' & 037 ) )
#else
if ( c == ('c' & 037 ) )
#endif
int_handler();
}
#endif