Beispiel #1
0
static void
RENDERER_Delay(Uint32 Tdelay)
{
	struct timespec ts, tsNow;
	int rv;

	AG_MutexLock(&agCondRenderLock);
	clock_gettime(CLOCK_MONOTONIC, &ts);
	ts.tv_sec += (Tdelay/1000);
	ts.tv_nsec += (Tdelay % 1000)*1000000;

	for (;;) {
		rv = AG_CondTimedWait(&agCondBeginRender, &agCondRenderLock, &ts);
		if (rv != 0) {
			clock_gettime(CLOCK_MONOTONIC, &tsNow);
			if (tsNow.tv_sec < ts.tv_sec) {
				continue;
			}
			if (tsNow.tv_sec > ts.tv_sec ||
			    tsNow.tv_nsec >= ts.tv_nsec)
				break;
		}
	}
	AG_MutexUnlock(&agCondRenderLock);
}
static void
Delay(Uint32 Tdelay)
{
	Uint32 t0, t, Telapsed = 0;
	struct timespec ts;

	AG_MutexLock(&agCondRenderLock);
	clock_gettime(CLOCK_REALTIME, &ts);
	ts.tv_sec += (Tdelay/1000);
	ts.tv_nsec += (Tdelay % 1000)*1000000;
	while (Telapsed < Tdelay) {
		t0 = GetTicks();
		if (AG_CondTimedWait(&agCondBeginRender,
		    &agCondRenderLock, &ts) != 0) {
			t = GetTicks();
			Telapsed += (t - t0);
		} else {
			AG_CondWait(&agCondEndRender, &agCondRenderLock);
		}
	}
	AG_MutexUnlock(&agCondRenderLock);
}