Exemple #1
0
int cond_wait_timed(bor_cond *cond, bor_mutex *mutex, int ms)
{
	struct timespec time_to_wait;
	time_to_wait.tv_sec = ms / 1000;
	time_to_wait.tv_nsec = ((long)(ms % 1000)) * 1000000;
	return LWP_RETCODE(LWP_CondTimedWait(*cond, *mutex, &time_to_wait));
}
Exemple #2
0
static void *gx_devthread(void *a)
{
   struct timespec timeout = {0};

   timeout.tv_sec = 1;
   timeout.tv_nsec = 0;

   while (1)
   {
      LWP_MutexLock(gx_device_mutex);
      unsigned i;
      for (i = 0; i < GX_DEVICE_END; i++)
      {
         if (gx_devices[i].mounted && !gx_devices[i].interface->isInserted())
         {
            gx_devices[i].mounted = false;
            char n[8];
            snprintf(n, sizeof(n), "%s:", gx_devices[i].name);
            fatUnmount(n);
         }
      }
      LWP_MutexUnlock(gx_device_mutex);
      LWP_MutexLock(gx_device_cond_mutex);
      LWP_CondTimedWait(gx_device_cond, gx_device_cond_mutex, &timeout);
      LWP_MutexUnlock(gx_device_cond_mutex);
   }

   return NULL;
}
int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
{
	struct timespec now;
	struct timespec abstime;

	if (!cond)
	{
		SDL_SetError("Passed a NULL condition variable");
		return -1;
	}

	clock_gettime(&now);

	abstime.tv_sec = now.tv_sec + (ms / 1000);
	abstime.tv_nsec = (now.tv_nsec + (ms % 1000) * 1000) * 1000;
	if (abstime.tv_nsec > 1000000000)
	{
		abstime.tv_sec += 1;
		abstime.tv_nsec -= 1000000000;
	}

	return LWP_CondTimedWait(cond->cond, mutex->id, &abstime);
}