阅读:1409回复:2
为什么互斥段进了2次?
环境为双核, 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) 当场就晕了,为什么居然进了两次呢? 谢谢 |
|
沙发#
发布于:2008-06-10 16:59
不太理解, windows call 工作项的时候可能在同一线程中 "同时" call 2次 ?
|
|
板凳#
发布于:2008-06-07 22:53
同一线程
|
|