引用: 引用 4 楼 flandy1982 的回复:
CMiniThread封装了线程相关的操作,方便使用.
封装的操作如下:
BOOL? ? ThreadStart(); // 如果创建的是挂起的线程, 需要调用此函数唤醒线程.
BOOL? ? ThreadStop(); // 如果线程是运行的, 挂起线程
BOOL? ? CeSetPriority( int nPriority ) // 设置线程优先级
BOOL? ? ThreadTerminated( DWORD dwMilliSeconds ) // 终止线程
BOOL? ? WaitThreadComplete( DWORD dwMilliSeconds ) // 等待线程结束
BOOL? ? ForceTerminated(); // 强行终止线程
DWORD GetThreadId(); // 获取线程id
BOOL IsTerminated(); // 线程是否终止
HANDLE GetThreadHandle(); 获取线程句柄
BOOL GetExitCodeThread( LPDWORD lpExitCode ); // 获取线程结束代码
更具体的细节可以参见微软提供的源代码:%WINCEROOT%\PUBLIC\COMMON\OAK\INC\cmthread.h
ThreadStart()只是将线程唤醒, 也就调用ResumeThread()函数
线程应该是运行起来了, CMiniThread::ThreadRun是怎么实现的?内部是否有等待的事件?
多谢啦!
以下是ThreadRun的实现,第一行的输出没打印出来过。
如果说ThreadStart是唤醒线程,那么唤醒后就是要执行ThreadRun函数了?
DWORD CameraHal::ThreadRun()
{
RETAILMSG(1, (_T("Entering %s\r\n"), _T(__FUNCTION__)));
while ( m_hCaptureEvent != NULL && !IsTerminated() )
{
DWORD dwCause;
RETAILMSG(CAMERA_HAL_DBG,(_T("%s() Waitfor Event: 0x%x\r\n"), _T(__FUNCTION__), m_hCaptureEvent));
dwCause = WaitForSingleObject( m_hCaptureEvent, m_dwISTTimeout);
if ( dwCause == WAIT_OBJECT_0 )
{
RETAILMSG(CAMERA_HAL_DBG,(_T("Event Catched from:0x%x(%d)\r\n"), m_hCaptureEvent, m_CamOperationMode));
if(m_CamOperationMode == VIDEO_CAPTURE)
{
if(m_dwSkipFrameCnt >= 1)
{
m_dwSkipFrameCnt = 2;
pfnCallbacks.pfnCameraHandleVideoFrame(pfnCallbacks.dwCameraDriverContext);
}
else
{
m_dwSkipFrameCnt++;
}
}
else if(m_CamOperationMode == STILL_CAPTURE)
{
// This will be taken on LAST IRQ
if(m_dwSkipFrameCnt >= 1)
{
m_dwSkipFrameCnt = 2;
SetEvent(m_hCaptureFinishEvent);
RETAILMSG(1,(TEXT("C%d\r\n"), m_dwSkipFrameCnt));
}
else
{
#if USE_LASTIRQ_STILLCAPTURE
m_regCAM->CIOCTRL |=(1<
m_regCAM->CIIMGCPT &= ~(CAM_GLOBAL_CAPTURE_ENABLE_BIT);
m_regCAM->CIOCTRL &= ~(1<
#endif
m_dwSkipFrameCnt++;
RETAILMSG(1,(TEXT("L%d\r\n"), m_dwSkipFrameCnt));
}
}
else if(m_CamOperationMode == PREVIEW_CAPTURE)
{
if(m_dwSkipFrameCnt >= 1)
{
m_dwSkipFrameCnt = 2;
pfnCallbacks.pfnCameraHandlePreviewFrame(pfnCallbacks.dwCameraDriverContext);
}
else
{
m_dwSkipFrameCnt ++;
}
}
if(m_CamOperationMode == POST_PROCESSOR)
{
SetEvent(m_hPostCmdDoneEvent);
}
// Clear Interrupt Pending
SET_BIT(m_regCAM->CIGCTRL, BP_CAM_IRQ_CLR);
SET_BIT(m_regCAM->CIOCTRL, BP_CAM_FRAME_END);
InterruptDone(m_CamSysIntr);
RETAILMSG(TRUE,(_T("%s(): PREVIEW INTR DOWN \r\n"), _T(__FUNCTION__)));
}
else
{
CAMIF_ERR((_T("[CAMIF:ERR] ++%s() : Exit %d, Cause %d\r\n"), _T(__FUNCTION__), GetLastError(), dwCause));
}
}
RETAILMSG(TRUE,(_T("%s(): Thread Finished"), _T(__FUNCTION__)));
return 1;
}