本文整理汇总了C++中SwitchToThread函数的典型用法代码示例。如果您正苦于以下问题:C++ SwitchToThread函数的具体用法?C++ SwitchToThread怎么用?C++ SwitchToThread使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SwitchToThread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LockMongoFilesShared
void ClientCursor::staticYield(int micros, const StringData& ns, const Record* rec) {
bool haveReadLock = Lock::isReadLocked();
killCurrentOp.checkForInterrupt( false );
{
auto_ptr<LockMongoFilesShared> lk;
if ( rec ) {
// need to lock this else rec->touch won't be safe file could disappear
lk.reset( new LockMongoFilesShared() );
}
dbtempreleasecond unlock;
if ( unlock.unlocked() ) {
if ( haveReadLock ) {
// This sleep helps reader threads yield to writer threads.
// Without this, the underlying reader/writer lock implementations
// are not sufficiently writer-greedy.
#ifdef _WIN32
SwitchToThread();
#else
if ( micros == 0 ) {
yieldOrSleepFor1Microsecond();
}
else {
sleepmicros(1);
}
#endif
}
else {
if ( micros == -1 ) {
sleepmicros(Client::recommendedYieldMicros());
}
else if ( micros == 0 ) {
yieldOrSleepFor1Microsecond();
}
else if ( micros > 0 ) {
sleepmicros( micros );
}
}
}
else if ( Listener::getTimeTracker() == 0 ) {
// we aren't running a server, so likely a repair, so don't complain
}
else {
CurOp * c = cc().curop();
while ( c->parent() )
c = c->parent();
warning() << "ClientCursor::yield can't unlock b/c of recursive lock"
<< " ns: " << ns
<< " top: " << c->info()
<< endl;
}
if ( rec )
rec->touch();
lk.reset(0); // need to release this before dbtempreleasecond
}
}
示例2: while
void CStressManager::DisconnectAll()
{
Zion::Map<_U32, CStressClient*>::iterator i;
_U32 count = 1;
while(count>0)
{
count = 0;
A_MUTEX_LOCK(&m_mtxLocker);
for(i=m_mapClients.begin(); i!=m_mapClients.end(); i++)
{
i->second->Logout();
if(i->second->GetClient()->GetState()!=CClient::STATE_NA && i->second->GetClient()->GetState()!=CClient::STATE_FAILED) count++;
}
A_MUTEX_UNLOCK(&m_mtxLocker);
SwitchToThread();
if(!CClientApp::GetDefault()->IsThread())
{
CClientApp::GetDefault()->Tick();
}
}
for(i=m_mapClients.begin(); i!=m_mapClients.end(); i++)
{
delete i->second;
}
m_mapClients.clear();
}
示例3: initWinSock
static int initWinSock(void)
{
WORD wVersionRequested;
WSADATA wsaData;
int i;
static LONG volatile initialized = 0;
wVersionRequested = MAKEWORD(1, 1);
if (InterlockedCompareExchange((LPLONG) &initialized,1L,0L) == 0L) {
/* FIXME not terminate, just a message?! */
if ((i = WSAStartup(wVersionRequested, &wsaData))) {
EI_TRACE_ERR1("ei_connect_init",
"ERROR: can't initialize windows sockets: %d",i);
initialized = 2L;
return 0;
}
if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1) {
EI_TRACE_ERR0("initWinSock","ERROR: this version of windows "
"sockets not supported");
WSACleanup();
initialized = 2L;
return 0;
}
initialized = 3L;
} else while (initialized < 2) {
SwitchToThread();
}
return (int) (initialized - 2);
}
示例4: fast_enter_critical_section
static __inline void fast_enter_critical_section(struct threadpool *tp)
{
sync_t *sync = (sync_t *) tp;
while (!TryEnterCriticalSection(&sync->critsec))
SwitchToThread();
}
示例5: rathread_yield
void rathread_yield(){
#ifdef WIN32
SwitchToThread();
#else
sched_yield();
#endif
}//end: rathread_yield()
示例6: GetTickCount
void CBufferOutputAudioEngine::Play()
{
//BufferTrace("CBufferOutputAudioEngine::Play()....\n");
if (!m_bFilled && m_mapOutputAudioBuf.size() < (1.0f*BUFFER_PERSEC_AUDIO_NUMBER*BUFFER_OUTPUT_ONMIC_AUDIO_MAX_LIMIT)/1000){
return ;
}
if (!m_bFilled) {
m_fLastPlayTime = GetTickCount();
m_iStartPlayCount = 0;
m_bFilled = true;
}
if (m_mapOutputAudioBuf.size() < 1 || (GetTickCount() - m_lastRecvTime) > 1000*10){//10s钟没有收到数据 超时 刷新
MutexLocker locker(&m_mutex);//播放线程 网络线程 m_mapOutputAudioBuf
ResetStatus();
return;
}
IsCanCalcRecvRate()?m_fRecvRate = CalcRecevRate():NULL;
m_fSendRate = CanCalcPlayRate();
//ErrTrace("CBufferOutputAudioEngine::Play() m_mapOutputAudioBuf.size()=%d,seq=%d,m_fRecvRate=%f,m_fSendRate=%f\n",m_mapOutputAudioBuf.size(),m_iMaxSequenceId - m_iMinSequenceId+1,m_fRecvRate,m_fSendRate);
unsigned int iLimit = 0;
DWORD dwCurrTime = GetTickCount();
while (m_fLastPlayTime < dwCurrTime && ++iLimit<5)
{
m_fLastPlayTime += m_fSendRate;
m_iStartPlayCount++;
PlayPackets();
SwitchToThread();
}
CheckPacket();
RefreshStatus();
}
示例7: StopIoTimer
BOOL StopIoTimer(LPTIMER lpTimer, BOOL bSkipActive)
{
// Sanity check
if (!lpTimer) return 0;
for (;;)
{
switch (InterlockedExchange(&lpTimer->lStatus, TIMER_CANCEL))
{
case TIMER_CANCEL:
case TIMER_ACTIVE:
// Timer procedure is currently active
if (bSkipActive) return -1;
SwitchToThread();
break;
case TIMER_WAIT:
// Timer is in wait state
EnterCriticalSection(&csIoTimer);
// Remove timer if it has not been posted
if (lpTimer->lStatus != TIMER_QUEUED) DeleteIoTimer(lpTimer);
LeaveCriticalSection(&csIoTimer);
Free(lpTimer);
return 0;
case TIMER_INACTIVE:
// Timer is inactive
Free(lpTimer);
return 1;
case TIMER_QUEUED:
return 0;
}
}
}
示例8: Thread_Yield
SO_PUBLIC void
Thread_Yield(void) {
#ifdef _MSC_VER
SwitchToThread();
#else
pthread_yield();
#endif
}
示例9: thread_rest
/*
* -------------------------------------------------------------------
* Allow another thread to execute. If no other threads are runable this
* is not guarenteed to actually rest.
* ------------------------------------------------------------------- */
void thread_rest ( void ) {
#if defined( HAVE_THREAD )
#if defined( HAVE_POSIX_THREAD )
#else // Win32
SwitchToThread( );
#endif
#endif
}
示例10: eUtils_ThreadYield
teUtilsStatus eUtils_ThreadYield(void)
{
#ifndef WIN32
sched_yield();
#else
SwitchToThread();
#endif
return E_UTILS_OK;
}
示例11: yieldOrSleepFor1Microsecond
void yieldOrSleepFor1Microsecond() {
#ifdef _WIN32
SwitchToThread();
#elif defined(__linux__)
pthread_yield();
#else
sleepmicros(1);
#endif
}
示例12: sched_yield
int sched_yield()
{
/* http://stackoverflow.com/questions/1383943/switchtothread-vs-sleep1
SwitchToThread(); was here. Unsure what's better for us, just trying.. */
if(!SwitchToThread())
Sleep(0);
return 0;
}
示例13: bg1
//The functions below should thread the while loop
static UINT bg1(LPVOID that) {
while (*lenref == 0) SwitchToThread();//sync (by using another long * as a temp)
fileDefault = CString(buff);
if (FileOpen(false)) {
run((CKODEKDlg *)that, ACTION_DECOMPRESS);
return 0;
}
run((CKODEKDlg *)that, END);
return -1;
}
示例14: DoWaitForReaders
VOID
WINAPI
DoWaitForReaders(IN PWAH_SEARCH_TABLE Table,
IN PVLONG Counter)
{
HANDLE EventHandle;
/* Do a context switch */
SwitchToThread();
/* Check if the counter is above one */
if (*Counter > 0)
{
/*
* This shouldn't happen unless priorities are messed up. Do a wait so
* that the threads with lower priority will get their chance now.
*/
if (!ghWriterEvent)
{
/* We don't even have an event! Allocate one manually... */
EventHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
if (EventHandle)
{
/* Save the event handle atomically */
if ((InterlockedCompareExchangePointer((PVOID*)&ghWriterEvent,
EventHandle,
NULL)))
{
/* Someone beat us to it, close ours */
CloseHandle(EventHandle);
}
}
else
{
/* Things couldn't get worse for us. Do a last-resort hack */
while (*Counter > 0) Sleep(10);
}
}
/*
* Our event is ready. Tell the others to signal us by making sure
* that the last counter will be -1, notifying the last thread of our
* request.
*/
if (InterlockedDecrement(Counter) >= 0)
{
/* Keep looping */
do
{
/* Wait in tiny bursts, so we can catch the PulseEvent */
WaitForSingleObject(ghWriterEvent, 10);
} while (*Counter >= 0);
}
}
}
示例15: WaitForWriteCapacity
void WaitForWriteCapacity(int amt)
{
for (; ; )
{
//dont return when available == amt because then we would consume the buffer and be unable to distinguish between full and empty
if (Available() > amt)
return;
//this is a greedy spinlock.
SwitchToThread();
}
}