watsonhua
驱动牛犊
驱动牛犊
  • 注册日期2008-04-23
  • 最后登录2009-07-27
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望24点
  • 贡献值0点
  • 好评度10点
  • 原创分0分
  • 专家分0分
阅读:1305回复:2

为什么互斥段进了2次?

楼主#
更多 发布于:2008-06-05 17:59
环境为双核, Vista
用互斥,代码大致如下:

#pragma LOCKEDCODE
VOID ProcessVideoQueue( PDEVICE_OBJECT fdo, PVIDEO_READ_JUNK junk )
{
    PIRP irp;
    KIRQL oldIrql;
    PUSBFX2LK_EXT devExt = (PUSBFX2LK_EXT) junk->devExt ;
    
    KeWaitForMutexObject( &(devExt->Mutex_VIDEO_CSQs), Executive, KernelMode, FALSE, NULL );
    OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_READWRITE, ("ProcessVideoQueue: Entered...\n"));

    KeAcquireSpinLock(&devExt->Lock_Video_FLAG_AND_STATE,&oldIrql);
    switch (devExt->STATE_VIDEO_FIFOFULL){
        case state_video_fifoNotFull:
            KeReleaseSpinLock(&devExt->Lock_Video_FLAG_AND_STATE,oldIrql);    
            OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_TEST|OSRDBG_READWRITE, ("ProcessVideoQueue:state_video_fifoNotFull \n"));                
            
            while( ( devExt->Count_IRPsInLowerDriver < MAX_COUNT_IRPS_IN_LOWERDRIVER )&&(irp = IoCsqRemoveNextIrp(&(devExt->Video_Read_IrpQueue.IrpCSQ), NULL)) ){
                VideoRead(devExt->FunctionalDeviceObject ,irp, FALSE );
                InterlockedIncrement(&(devExt->Count_IRPsInLowerDriver));
                OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_TEST|OSRDBG_READWRITE, ("ProcessVideoQueue: Send a IRP from video read queue...\n"));                
            }
            break;
        default:
            KeReleaseSpinLock(&devExt->Lock_Video_FLAG_AND_STATE,oldIrql);
            break;            
    }
    OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_TEST|OSRDBG_READWRITE,("ProcessVideoQueue: Exit (%d irps in Lower Driver)\n", devExt->Count_IRPsInLowerDriver));
    KeReleaseMutex( &(devExt->Mutex_VIDEO_CSQs), FALSE );
    IoFreeWorkItem(junk->item);
    ExFreePool(junk);    
}

运行结果如下:
ProcessVideoQueue: Entered...
ProcessVideoQueue:state_video_fifoNotFull
Video_Read_CsqPeekNextIoIrp: Peeking next Irp from the head of the queue...
Video_Read_CsqPeekNextIoIrp: Next Irp is Irp 0x00000000...
Video_Read_CsqPeekNextIoIrp: Peeking next Irp from the head of the queue...
Video_Read_CsqPeekNextIoIrp: Next Irp is Irp 0x00000000...
Video_Read_CsqPeekNextIoIrp: Peeking next Irp from the head of the queue...
Video_Read_CsqPeekNextIoIrp: Next Irp is Irp 0x86B11ED8...
Video_Read_CsqRemoveIoIrp: Removing Irp 0x86B11ED8 from the cancel safe queue...
UsbFx2LkReadCompletionRoutine: Irp 0x85790AF8 Receive Complete (829440 of 829440 bytes).
UsbFx2LkReadCompletionRoutine:  ()Exit Successful.
ProcessVideoQueue: Entered...
ProcessVideoQueue:state_video_fifoNotFull
Video_Read_CsqPeekNextIoIrp: Peeking next Irp from the head of the queue...
Video_Read_CsqPeekNextIoIrp: Next Irp is Irp 0x00000000...
Video_Read_CsqPeekNextIoIrp: Peeking next Irp from the head of the queue...
Video_Read_CsqPeekNextIoIrp: Next Irp is Irp 0x00000000...
Video_Read_CsqPeekNextIoIrp: Peeking next Irp from the head of the queue...
Video_Read_CsqPeekNextIoIrp: Next Irp is Irp 0x00000000...
ProcessVideoQueue: Exit (2 irps in Lower Driver)

当场就晕了,为什么居然进了两次呢?
谢谢
eleqi
驱动小牛
驱动小牛
  • 注册日期2005-12-20
  • 最后登录2014-01-03
  • 粉丝4
  • 关注2
  • 积分172分
  • 威望1475点
  • 贡献值0点
  • 好评度115点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2008-06-07 22:53
同一线程
watsonhua
驱动牛犊
驱动牛犊
  • 注册日期2008-04-23
  • 最后登录2009-07-27
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望24点
  • 贡献值0点
  • 好评度10点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2008-06-10 16:59
不太理解,  windows call 工作项的时候可能在同一线程中 "同时" call 2次 ?
游客

返回顶部