当前位置: 首页>>代码示例>>C++>>正文


C++ SleepConditionVariableCS函数代码示例

本文整理汇总了C++中SleepConditionVariableCS函数的典型用法代码示例。如果您正苦于以下问题:C++ SleepConditionVariableCS函数的具体用法?C++ SleepConditionVariableCS怎么用?C++ SleepConditionVariableCS使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SleepConditionVariableCS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: defined

	void Conditional::Wait(Mutex *mutex, Int microseconds) {
		//printf("Wait(%s) start\n", mName.GetCString());
	#if defined(FastOSWindows)
		if (0 > microseconds)
			SleepConditionVariableCS(&mConditionVariable->cv,
				&mutex->GetCriticalSection()->cs, INFINITE);
		else
			SleepConditionVariableCS(&mConditionVariable->cv,
				&mutex->GetCriticalSection()->cs, microseconds / 1000);
	#elif defined(FastOSUnixLike)
		if (0 > microseconds)
			pthread_cond_wait(&mConditionVariable->cv,
				&mutex->GetCriticalSection()->cs);
		else {
			struct timespec timeToWait;
			struct timeval now;
			gettimeofday(&now, NULL);
			timeToWait.tv_sec = now.tv_sec + (microseconds / 1000000);
			timeToWait.tv_nsec = 1000 * (now.tv_usec + (microseconds -
				((microseconds / 1000000) * 1000000)));
			pthread_cond_timedwait(&mConditionVariable->cv,
				&mutex->GetCriticalSection()->cs, &timeToWait);
		}
	#endif
		//printf("Wait(%s) end\n", mName.GetCString());
	}
开发者ID:JSandrew4,项目名称:FastGdk,代码行数:26,代码来源:Conditional.cpp

示例2: gpr_cv_wait

int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) {
  int timeout = 0;
  DWORD timeout_max_ms;
  mu->locked = 0;
  if (gpr_time_cmp(abs_deadline, gpr_inf_future(abs_deadline.clock_type)) ==
      0) {
    SleepConditionVariableCS(cv, &mu->cs, INFINITE);
  } else {
    gpr_timespec now = gpr_now(abs_deadline.clock_type);
    int64_t now_ms = (int64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000;
    int64_t deadline_ms =
        (int64_t)abs_deadline.tv_sec * 1000 + abs_deadline.tv_nsec / 1000000;
    if (now_ms >= deadline_ms) {
      timeout = 1;
    } else {
      if ((deadline_ms - now_ms) >= INFINITE) {
        timeout_max_ms = INFINITE - 1;
      } else {
        timeout_max_ms = (DWORD)(deadline_ms - now_ms);
      }
      timeout = (SleepConditionVariableCS(cv, &mu->cs, timeout_max_ms) == 0 &&
                 GetLastError() == ERROR_TIMEOUT);
    }
  }
  mu->locked = 1;
  return timeout;
}
开发者ID:nimrodp,项目名称:grpc,代码行数:27,代码来源:sync_win32.c

示例3: condition_Wait

EXEC_RETURN condition_Wait(CONDITION* condition,CS_LOCK* cs,unsigned long msec){
#if defined(WIN32) || defined(_WIN64)
	return SleepConditionVariableCS(condition,cs,msec) ? EXEC_SUCCESS:EXEC_ERROR;
#else
	int res;
	if(msec == ~0){
		res = pthread_cond_wait(condition,cs);
		if(res)
			goto err;
	}else{
		struct timeval utc = {0};
		struct timespec time_val = {0};
		if(!gettimeofday(&utc,NULL)){
			time_val.tv_sec = utc.tv_sec + msec / 1000;
			msec %= 1000;
			time_val.tv_nsec = utc.tv_usec * 1000 + msec * 1000000;
			res = pthread_cond_timedwait(condition,cs,&time_val);
			if(res)
				goto err;
		}else
			return EXEC_ERROR;
	}
	return EXEC_SUCCESS;
err:
	errno = res;
	return EXEC_ERROR;
#endif
}
开发者ID:mildrock,项目名称:server-cpp,代码行数:28,代码来源:ipc.c

示例4: YabThreadRemoteSleep

void YabThreadRemoteSleep(unsigned int id) 
{
   if (!thread_handle[id].thd)
      return;  // Thread wasn't running in the first place

   SleepConditionVariableCS(&thread_handle[id].cond, &thread_handle[id].mutex, INFINITE);
}
开发者ID:em4pixeleen,项目名称:yabause,代码行数:7,代码来源:thr-windows.c

示例5: SleepConditionVariableCS

//==============================================================================
void ConditionVariable::wait(Mutex& amtx)
{
	CONDITION_VARIABLE* cond = reinterpret_cast<CONDITION_VARIABLE*>(m_impl);
	CRITICAL_SECTION* mtx = reinterpret_cast<CRITICAL_SECTION*>(amtx.m_impl);

	SleepConditionVariableCS(cond, mtx, INFINITE);
}
开发者ID:zhouxh1023,项目名称:anki-3d-engine,代码行数:8,代码来源:ThreadWindows.cpp

示例6: pthread_cond_wait

void SkCondVar::wait() {
#ifdef SK_USE_POSIX_THREADS
    pthread_cond_wait(&fCond, &fMutex);
#elif defined(SK_BUILD_FOR_WIN32)
    SleepConditionVariableCS(&fCondition, &fCriticalSection, INFINITE);
#endif
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:7,代码来源:SkCondVar.cpp

示例7: pthread_cond_timedwait

int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, struct timespec* abstime)
{
    DWORD timeout = get_milliseconds(abstime);
    if (!SleepConditionVariableCS(cond, mutex, timeout))
        return ETIMEDOUT;
    return 0;
}
开发者ID:HengWang,项目名称:my_libs,代码行数:7,代码来源:my_pthread.c

示例8: ProducerThreadProc

DWORD WINAPI ProducerThreadProc (PVOID p)
{
	ULONG ProducerId = (ULONG)(ULONG_PTR)p;
	while (true)
	{
		// Produce a new item.
		Sleep(rand() % PRODUCER_SLEEP_TIME_MS);
		ULONG Item = InterlockedIncrement(&LastItemProduced);
		EnterCriticalSection(&BufferLock);
		while (QueueSize == BUFFER_SIZE && StopRequested == FALSE)
		{
			// Buffer is full - sleep so consumers can get items.
			SleepConditionVariableCS(&BufferNotFull, &BufferLock, INFINITE);
		}
		if (StopRequested == TRUE)
		{
			LeaveCriticalSection(&BufferLock);
			break;
		}
		// Insert the item at the end of the queue and increment size.
		Buffer[(QueueStartOffset + QueueSize) % BUFFER_SIZE] = Item;
		++QueueSize;
		++TotalItemsProduced;
		printf("Producer %u: item %2d, queue size %2u\r\n", ProducerId, Item, QueueSize);
		LeaveCriticalSection(&BufferLock);
		// If a consumer is waiting, wake it.
		WakeConditionVariable(&BufferNotEmpty);
	}
	printf("Producer %u exiting\r\n", ProducerId);
	return 0;
}
开发者ID:chengguixing,项目名称:iArt,代码行数:31,代码来源:main.cpp

示例9: ConsumerThreadProc

DWORD WINAPI ConsumerThreadProc (PVOID p)
{
	ULONG ConsumerId = (ULONG)(ULONG_PTR)p;
	while (true)
	{
		EnterCriticalSection(&BufferLock);
		while (QueueSize == 0 && StopRequested == FALSE)
		{
			// Buffer is empty - sleep so producers can create items.
			SleepConditionVariableCS(&BufferNotEmpty, &BufferLock, INFINITE);
		}
		if (StopRequested == TRUE && QueueSize == 0)
		{
			LeaveCriticalSection(&BufferLock);
			break;
		}
		// Consume the first available item.
		LONG Item = Buffer[QueueStartOffset];
		--QueueSize;
		++QueueStartOffset;
		++TotalItemsConsumed;
		if (QueueStartOffset == BUFFER_SIZE)
		{
			QueueStartOffset = 0;
		}
		printf("Consumer %u: item %2d, queue size %2u\r\n", ConsumerId, Item, QueueSize);
		LeaveCriticalSection(&BufferLock);
		// If a producer is waiting, wake it.
		WakeConditionVariable(&BufferNotFull);
		// Simulate processing of the item.
		Sleep(rand() % CONSUMER_SLEEP_TIME_MS);
	}
	printf("Consumer %u exiting\r\n", ConsumerId);
	return 0;
}
开发者ID:chengguixing,项目名称:iArt,代码行数:35,代码来源:main.cpp

示例10: SleepConditionVariableCS

	bool ConditionVariableImpl::Wait(MutexImpl* mutex, UInt32 timeout)
	{
		#if NAZARA_CORE_WINDOWS_VISTA
		return SleepConditionVariableCS(&m_cv, &mutex->m_criticalSection, timeout);
		#else
		m_count++;

		// It's ok to release the mutex here since Win32
		// manual-reset events maintain state when used with SetEvent.
		// This avoids the "lost wakeup" bug...
		LeaveCriticalSection(&mutex->m_criticalSection);

		// Wait for either event to become signaled due to Signal being called or SignalAll being called.
		int result = WaitForMultipleObjects(2, m_events, false, timeout);

		// Some thread called SignalAll
		if (--m_count == 0 && result == WAIT_OBJECT_0 + BROADCAST)
			// We're the last waiter to be notified or to stop waiting, so reset the manual event.
			ResetEvent(m_events[BROADCAST]);

		// Reacquire the mutex.
		EnterCriticalSection(&mutex->m_criticalSection);

		return result != WAIT_TIMEOUT;
		#endif
	}
开发者ID:GigAnon,项目名称:NazaraEngine,代码行数:26,代码来源:ConditionVariableImpl.cpp

示例11: nn_condvar_wait

int nn_condvar_wait (nn_condvar_t *cond, nn_mutex_t *lock, int timeout)
{
    BOOL brc;
    DWORD expire;

    /*  Likely this is redundant, but for API correctness be explicit. */
    expire = (timeout < 0) ? INFINITE : (DWORD) timeout;

    /*  We must own the lock if we are going to call this. */
    nn_assert (lock->owner == GetCurrentThreadId());
    /*  Clear ownership as SleepConditionVariableCS will drop it. */
    lock->owner = 0;

    brc = SleepConditionVariableCS (&cond->cv, &lock->cs, expire);

    /*  We have reacquired the lock, so nobody should own it right now. */
    nn_assert (lock->owner == 0);
    /*  Note we own it now. */
    lock->owner = GetCurrentThreadId();

    if (!brc && GetLastError () == ERROR_TIMEOUT) {
        return (-ETIMEDOUT);
    }
    return (0);
}
开发者ID:Adellica,项目名称:nanomsg,代码行数:25,代码来源:condvar.c

示例12: r_cond_wait_timed

rboolean
r_cond_wait_timed (RCond * cond, RMutex * mutex, rulong microsec)
{
  rboolean ret;
#if defined (R_OS_WIN32)
  if (!(ret = SleepConditionVariableCS ((PCONDITION_VARIABLE)*cond,
      (LPCRITICAL_SECTION)*mutex, microsec / 1000))) {
    /* GetLastError () should be ERROR_TIMEOUT */
  }
#elif defined (HAVE_PTHREAD_H)
  struct timespec expire;
  int waitret;
  clock_gettime (CLOCK_MONOTONIC, &expire)
  expire.tv_sec = microsec / R_USEC_PER_SEC;
  expire.tv_nsec = 1000 * (microsec % R_USEC_PER_SEC);
  waitret = pthread_cond_timedwait ((pthread_cond_t *)*cond,
      (pthread_mutex_t *)*mutex, &expire);

  if (!(ret = (waitret == 0))) {
    /* waitret should be ETIMEDOUT */
  }
#else
  (void) cond;
  ret = FALSE;
#endif
  return ret;
}
开发者ID:ieei,项目名称:rlib,代码行数:27,代码来源:rthreads.c

示例13: ANKI_ASSERT

//==============================================================================
Bool Barrier::wait()
{
	ANKI_ASSERT(m_impl);
	BarrierImpl& barrier = *reinterpret_cast<BarrierImpl*>(m_impl);

	EnterCriticalSection(&barrier.m_mtx);
	U32 gen = barrier.m_generation;

	if(--barrier.m_count == 0)
	{
		++barrier.m_generation;
		barrier.m_count = barrier.m_threshold;
		WakeAllConditionVariable(&barrier.m_cvar);
		LeaveCriticalSection(&barrier.m_mtx);
		return true;
	}

	while(gen == barrier.m_generation)
	{
		SleepConditionVariableCS(&barrier.m_cvar, &barrier.m_mtx, INFINITE);
	}

	LeaveCriticalSection(&barrier.m_mtx);
	return false;
}
开发者ID:zhouxh1023,项目名称:anki-3d-engine,代码行数:26,代码来源:ThreadWindows.cpp

示例14: embb_condition_wait_until

int embb_condition_wait_until(embb_condition_t* condition_var,
                              embb_mutex_t* mutex, const embb_time_t* time) {
  assert(condition_var != NULL);
  assert(mutex != NULL);
  assert(time != NULL);
  /* The Windows API needs a time duration, so we need to convert the given time
     by using the time now. */
  embb_time_t now;
  embb_time_now(&now);
  /* Check if absolute timepoint (in milliseconds) still is in the future */
  if ((time->seconds * 1000 + time->nanoseconds / 1000000)
      > (now.seconds * 1000 + now.nanoseconds / 1000000)) {
    /* Convert to (unsigned type) milliseconds and round up */
    DWORD time_diff = (DWORD) (
        time->seconds * 1000 + time->nanoseconds / 1000000
        - now.seconds * 1000 - now.nanoseconds / 1000000);
    if (SleepConditionVariableCS(condition_var, mutex, time_diff) == 0) {
      if (GetLastError() == ERROR_TIMEOUT) {
        return EMBB_TIMEDOUT;
      } else {
        return EMBB_ERROR;
      }
    }
  } else {
    return EMBB_TIMEDOUT;
  }
  return EMBB_SUCCESS;
}
开发者ID:danklmn,项目名称:embb,代码行数:28,代码来源:condition_variable.c

示例15: pthread_cond_timedwait

/**
@Status Caveat
@Notes Error return codes ignored. Only ETIMEDOUT is supported, otherwise windows errors are used.
*/
extern "C" int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const struct timespec* ts) {
    if (*((uint32_t*)cond) == PTHREAD_COND_INITIALIZER) {
        pthread_cond_init(cond, 0);
    }
    if (*mutex == PTHREAD_MUTEX_INITIALIZER) {
        pthread_mutex_init(mutex, 0);
    }
    EbrTimeval tv;
    EbrGetTimeOfDay(&tv);

    uint64_t curNanoseconds = ((uint64_t)tv.tv_sec) * 1000 * 1000 * 1000 + ((uint64_t)tv.tv_usec) * 1000;
    uint64_t timeoutNS = ((uint64_t)ts->tv_sec) * 1000 * 1000 * 1000 + (uint64_t)ts->tv_nsec;
    int64_t waitNS = timeoutNS - curNanoseconds;
    if (waitNS < 0)
        waitNS = 0;

    int retVal = 0;
    DWORD ms = waitNS / 1000000;

    DWORD ret = SleepConditionVariableCS((CONDITION_VARIABLE*)*cond, (CRITICAL_SECTION*)*mutex, ms);
    if (ret) {
        retVal = 0;
    } else {
        retVal = ETIMEDOUT;
    }

    return retVal;
}
开发者ID:CoderMessi,项目名称:WinObjC,代码行数:32,代码来源:pthread.cpp


注:本文中的SleepConditionVariableCS函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。