示例#1
0
void SetUpTimers(void)
{
    extern void ioInitTime(void);

    /* set up the backwardcompatibility micro/millisecond clock */
    gettimeofday(&startUpTime, 0);
    /* setup the spiffy new 64-bit microsecond clock. */
    ioInitTime();
}
int
main(int argc, char *argv[])
{
	int err;

	signal(SIGINT, lockedup);
	ioVMThread = pthread_self();
	ioInitTime();
	ioInitHeartbeat();
	addSynchronousTickee(printAndQuit, SECS * 1000, 0);
	if (argc > 1) {
		method = argv[1];
		if (!strcmp(argv[1],"none"))
			yieldMethod = no_yield;
		else if (!strcmp(argv[1],"sched_yield"))
			yieldMethod = yield_via_sched_yield;
		else if (!strcmp(argv[1],"pthread_yield"))
			yieldMethod = yield_via_pthread_yield;
		else if (!strcmp(argv[1],"nanosleep"))
			yieldMethod = yield_via_nanosleep;
		else if (!strcmp(argv[1],"cond_timedwait")) {
			if ((err = pthread_mutex_lock(&yield_mutex)))
				return 2;
			yieldMethod = yield_via_cond_timedwait;
		}
		else if (!strcmp(argv[1],"wait_signal"))
			yieldMethod = yield_via_wait_signal;
		else {
			fprintf(stderr,
					"usage: %s [none] [sched_yield] [nanosleep] [cond_timedwait] [wait_signal] [yield usecs]\n",
					argv[0]);
			return 3;
		}
		if (argc > 2)
			yieldusecs = atoi(argv[2]);

#if !YIELD_IN_TICKER
		addSynchronousTickee(maybeYield, 2, 0);
#endif /* !YIELD_IN_TICKER */
	}
	addHighPriorityTickee(hptick, hptickperiodms);
	fakevm();
	/* should exit through printAndQuit */
	return 1;
}