⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 carbthrd.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    const BOOL bSkipParam1   = (pMatch->m_pParam1 == NULL);    const BOOL bSkipParam2   = (pMatch->m_pParam2 == NULL);    while((osResult = ::MPWaitOnQueue(m_mpQueueID, &param1, &param2, &param3, kDurationImmediate)) == noErr)    {                // does it match?        if( ( bSkipMessage || pMatch->m_ulMessage == (UINT32) param1 ) &&            ( bSkipParam1  || pMatch->m_pParam1 == param2 ) &&            ( bSkipParam2  || pMatch->m_pParam2 == param3 ) )        {            foundAMatch = TRUE;            break;        }                // copy it into the temp queue        ::MPNotifyQueue(tempQ, param1, param2, param3);    }        if( foundAMatch )    {	// copy the found message to the out variable	pMsg->m_ulMessage = (UINT32)param1;	pMsg->m_pParam1 = param2;	pMsg->m_pParam2 = param3;			// if we aren't supposed to remove it, re-post it	if( !bRemoveMessage )	{	    ::MPNotifyQueue(tempQ, param1, param2, param3);	}			// now copy any remaining messages        while((osResult = ::MPWaitOnQueue(m_mpQueueID, &param1, &param2, &param3, kDurationImmediate)) == noErr)        {            ::MPNotifyQueue(tempQ, param1, param2, param3);        }                retval = HXR_OK;    }    else    {        pMsg->m_ulMessage = 0;        retval = HXR_FAIL;    }        // now that the original queue is empty, throw it away and keep the copy that we made    ::MPDeleteQueue(m_mpQueueID);    m_mpQueueID = tempQ;    m_pQueueMutex->Unlock();    return retval;}HX_RESULTHXCarbonThread::DispatchMessage(HXThreadMessage* pMsg){    HX_RESULT retval = HXR_NOTIMPL;    HX_ASSERT(!"Unimplemented DispatchMessage!");    return retval;}// HXCarbonEventHXCarbonEvent::HXCarbonEvent(const char* pEventName, BOOL bManualReset)  : m_mpSemaphoreID(NULL)  , m_IsManuallyReset( bManualReset ){    MPSemaphoreCount semaphoreMax = bManualReset ? INT_MAX : 1;    OSStatus osStatus = ::MPCreateSemaphore(semaphoreMax, 0, &m_mpSemaphoreID);    HX_ASSERT(osStatus == noErr);}HXCarbonEvent::~HXCarbonEvent(){    OSStatus osStatus = ::MPDeleteSemaphore(m_mpSemaphoreID);    m_mpSemaphoreID = NULL;    HX_ASSERT(osStatus == noErr);}HX_RESULTHXCarbonEvent::SignalEvent(void){    HX_RESULT retval = HXR_OK;    OSStatus osStatus = ::MPSignalSemaphore(m_mpSemaphoreID);    if (osStatus != noErr && osStatus != kMPInsufficientResourcesErr) retval = HXR_FAIL;        return retval;}HX_RESULTHXCarbonEvent::ResetEvent(void){    HX_RESULT retval = HXR_OK;    OSStatus osStatus;        while(noErr == (osStatus = ::MPWaitOnSemaphore(m_mpSemaphoreID, kDurationImmediate)))    {    }        return retval;}void*HXCarbonEvent::GetEventHandle(void){    return (void*)m_mpSemaphoreID;}HX_RESULTHXCarbonEvent::Wait(UINT32 uTimeoutPeriod){    HX_RESULT retval = HXR_OK;        Duration timeout = ( uTimeoutPeriod == ALLFS ) ? kDurationForever : ( uTimeoutPeriod * kDurationMillisecond );        OSStatus osStatus = ::MPWaitOnSemaphore(m_mpSemaphoreID, timeout);        switch (osStatus)    {	case noErr:	    if( m_IsManuallyReset )	    {	    	// needs to go back into the raised state until Reset is explicitly called	    	::MPSignalSemaphore(m_mpSemaphoreID);	    }	    retval = HXR_OK;	    break;		case kMPTimeoutErr:	    retval = HXR_WOULD_BLOCK; // winthrd.cpp returns this if the wait times out	    break;		default:	    retval = HXR_FAIL;	    break;    }        return retval;}// HXCarbonManualEventHXCarbonManualEvent::HXCarbonManualEvent(const char* pEventName) : m_pMutex(NULL) , m_bIsSignalled(FALSE) , m_InternalSemaphoreID(NULL){    HXMutex::MakeMutex(m_pMutex);    OSStatus osStatus = ::MPCreateSemaphore(1, 0, &m_InternalSemaphoreID);}HXCarbonManualEvent::~HXCarbonManualEvent(){    OSStatus osStatus = ::MPDeleteSemaphore(m_InternalSemaphoreID);    m_InternalSemaphoreID = NULL;    HX_DELETE(m_pMutex);}HX_RESULTHXCarbonManualEvent::SignalEvent(){    m_pMutex->Lock();    m_bIsSignalled = TRUE;    ::MPSignalSemaphore(m_InternalSemaphoreID); // in case we're waiting.    m_pMutex->Unlock();        return HXR_OK;}HX_RESULTHXCarbonManualEvent::ResetEvent(){    m_pMutex->Lock();    m_bIsSignalled = FALSE;    ::MPWaitOnSemaphore(m_InternalSemaphoreID, kDurationImmediate); // just clear it out...    m_pMutex->Unlock();    return HXR_OK;}HX_RESULTHXCarbonManualEvent::Wait(UINT32 uTimeoutPeriod){    BOOL bDone = FALSE;        HX_RESULT retVal = HXR_OK;        while (!bDone)    {	m_pMutex->Lock();	BOOL bIsSignalled = m_bIsSignalled;	m_pMutex->Unlock();	if (bIsSignalled)	{	    bDone = TRUE;	}	else	{	    // xxxbobclark rely on MP semaphore	    	    Duration timeout = ( uTimeoutPeriod == ALLFS ) ? kDurationForever : ( uTimeoutPeriod * kDurationMillisecond );	    	    OSStatus osStatus = ::MPWaitOnSemaphore(m_InternalSemaphoreID, timeout);	    bDone = TRUE;	    if (osStatus == kMPTimeoutErr)	    {		retVal = HXR_WOULD_BLOCK;	    }	}    }    return retVal;}void*HXCarbonManualEvent::GetEventHandle	(void){    return (void*)this;}// HXCarbonMutexHXCarbonMutex::HXCarbonMutex(){    MPCreateCriticalRegion(&mCriticalRegion);}HXCarbonMutex::~HXCarbonMutex(){    MPDeleteCriticalRegion(mCriticalRegion);}HX_RESULTHXCarbonMutex::Lock(void){    MPEnterCriticalRegion(mCriticalRegion, kDurationForever);    return HXR_OK;}HX_RESULTHXCarbonMutex::Unlock(void){    MPExitCriticalRegion(mCriticalRegion);    return HXR_OK;}HX_RESULTHXCarbonMutex::Trylock(void){    HX_RESULT retval = HXR_OK;    OSStatus osStatus = MPEnterCriticalRegion(mCriticalRegion, kDurationImmediate);        if (osStatus != noErr)    {    	retval = HXR_FAIL;    }     return retval;}//HXCarbonSemaphoreHXCarbonSemaphore::HXCarbonSemaphore( UINT32 unInitialCount /*=0*/)					:m_mpSemaphoreID(0){   OSStatus osStatus = ::MPCreateSemaphore(INT_MAX, unInitialCount, &m_mpSemaphoreID);      HX_ASSERT(osStatus == noErr);}HXCarbonSemaphore::~HXCarbonSemaphore(){	MPDeleteSemaphore(m_mpSemaphoreID);}HX_RESULT HXCarbonSemaphore::Post(){	HX_RESULT retval = HXR_OK;		OSStatus osStatus = MPSignalSemaphore(m_mpSemaphoreID);		if (osStatus != noErr)	{		retval = HXR_FAIL;	}		return retval; }HX_RESULT HXCarbonSemaphore::Wait(){	HX_RESULT retval = HXR_OK;		OSStatus osStatus = MPWaitOnSemaphore(m_mpSemaphoreID, kDurationForever);		if (osStatus != noErr)	{		retval = HXR_FAIL;	}	    		return retval;}HX_RESULT HXCarbonSemaphore::TryWait(){	HX_RESULT retval = HXR_OK;		OSStatus osStatus = MPWaitOnSemaphore(m_mpSemaphoreID, kDurationImmediate);		if (osStatus != noErr)	{		retval = HXR_FAIL;	}		return retval;}	#if 0// HXCarbonAsyncTimerHXCarbonAsyncTimer::HXCarbonAsyncTimer(ULONG32 ulTimeOut, HXThread* pReceivingThread) : m_ulTimeout(ulTimeOut) , m_pReceivingThread(pReceivingThread) , m_CarbonTimerUPP(NULL) , m_CarbonTimerRef(NULL) , m_msg(NULL){    m_msg = new HXThreadMessage(HXMSG_ASYNC_TIMER, (void*)m_ulTimeout, NULL, NULL);    m_CarbonTimerUPP = ::NewEventLoopTimerUPP((EventLoopTimerProcPtr)MyCarbonTimer);    ::InstallEventLoopTimer(GetCurrentEventLoop(), 0, kEventDurationMillisecond *		m_ulTimeout, m_CarbonTimerUPP, this, &m_CarbonTimerRef);}HXCarbonAsyncTimer::~HXCarbonAsyncTimer(){    if (m_CarbonTimerRef)    {	::RemoveEventLoopTimer(m_CarbonTimerRef);	m_CarbonTimerRef = NULL;    }    if (m_CarbonTimerUPP)    {	::DisposeEventLoopTimerUPP(m_CarbonTimerUPP);	m_CarbonTimerUPP = NULL;    }    delete m_msg;}/* static */UINT32HXCarbonAsyncTimer::SetTimer(ULONG32 ulTimeOut, HXThread* pReceivingThread){    volatile HXCarbonAsyncTimer* pAsyncTimer = new HXCarbonAsyncTimer(ulTimeOut, pReceivingThread);    return (UINT32) pAsyncTimer;}/* static */voidHXCarbonAsyncTimer::MyCarbonTimer(EventLoopTimerRef, HXCarbonAsyncTimer* pAsyncTimer){    HX_ASSERT(pAsyncTimer);    HX_ASSERT(pAsyncTimer->m_pReceivingThread);    HXThreadMessage theMsg(HXMSG_ASYNC_TIMER, (void*)pAsyncTimer->m_ulTimeout, NULL, NULL);    pAsyncTimer->m_pReceivingThread->PostMessage(&theMsg);}#endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -