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


C++ SwitchToThread函数代码示例

本文整理汇总了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
        }
    }
开发者ID:ChrisBg,项目名称:mongo,代码行数:60,代码来源:clientcursor.cpp

示例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();
	}
开发者ID:luozhishen,项目名称:gameengine,代码行数:28,代码来源:StressManager.cpp

示例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);
}
开发者ID:3112517927,项目名称:otp,代码行数:31,代码来源:ei_connect.c

示例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();
}
开发者ID:project-hephaestus,项目名称:electric_train,代码行数:7,代码来源:threadpool.c

示例5: rathread_yield

void rathread_yield(){
#ifdef WIN32
	SwitchToThread();
#else
	sched_yield();
#endif
}//end: rathread_yield()
开发者ID:RagnarokTales,项目名称:Hercules,代码行数:7,代码来源:thread.c

示例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();
}
开发者ID:fffonion,项目名称:V8,代码行数:35,代码来源:BufferOutputAudioEngine.cpp

示例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;
        }
    }
}
开发者ID:as2120,项目名称:ZioFtpd,代码行数:32,代码来源:Timer.c

示例8: Thread_Yield

SO_PUBLIC void
Thread_Yield(void) {
#ifdef _MSC_VER
	SwitchToThread();
#else
	pthread_yield();
#endif
}
开发者ID:CERT-Polska,项目名称:hsn2-razorback,代码行数:8,代码来源:thread.c

示例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
}
开发者ID:AnupBansod,项目名称:andro-iperf,代码行数:13,代码来源:Thread.c

示例10: eUtils_ThreadYield

teUtilsStatus eUtils_ThreadYield(void)
{
#ifndef WIN32
    sched_yield();
#else
    SwitchToThread();
#endif
    return E_UTILS_OK;
}
开发者ID:lewisling,项目名称:ZigbeeNodeControlBridge2V1_WiFiGateway,代码行数:9,代码来源:Utils.c

示例11: yieldOrSleepFor1Microsecond

    void yieldOrSleepFor1Microsecond() {
#ifdef _WIN32
        SwitchToThread();
#elif defined(__linux__)
        pthread_yield();
#else
        sleepmicros(1);
#endif
    }
开发者ID:EshaMaharishi,项目名称:pubsub,代码行数:9,代码来源:clientcursor.cpp

示例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;
}
开发者ID:Ferada,项目名称:sbcl,代码行数:9,代码来源:pthreads_win32.c

示例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;
}
开发者ID:jackokring,项目名称:KODEK,代码行数:11,代码来源:KODEKDlg.cpp

示例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);
        }
    }
}
开发者ID:RareHare,项目名称:reactos,代码行数:55,代码来源:context.c

示例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();
		}
	}
开发者ID:zeromus,项目名称:BizHawk,代码行数:11,代码来源:libsnes_pwrap.cpp


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