#include <sys/time.h>
#include <unistd.h>
#include <string.h>

#define DELAY 33333

int drmWaitVBlank(void)
{
static struct timeval last = { 0, 0 };
static struct timeval now  = { 0, 0 };
int udiff;

gettimeofday(&now, NULL);
udiff = (int)now.tv_usec - (int)last.tv_usec;
if (udiff < 0)
udiff += 1000000;
udiff -= DELAY;
if (udiff < 0)
usleep(-udiff);
memcpy(&last, &now, sizeof(struct timeval));

return 0;
}

