Does WdfIoQueueGetState must be called before WdfIoQueueRetrieveNextRequest on a manual queue?

Hi All
I created two queues
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&defaultQueueConfig, WdfIoQueueDispatchParallel);
defaultQueueConfig.EvtIoDeviceControl = ControllerEvtIoDeviceControl;
defaultQueueConfig.PowerManaged = WdfFalse;
status = WdfIoQueueCreate(wdfDevice, &defaultQueueConfig, WDF_NO_OBJECT_ATTRIBUTES, &usbContext->DefaultQueue);
if (!NT_SUCCESS(status)) {
DbgPrint(“Default queue creation failed %d”, status);
goto exit;
}

	WDF_IO_QUEUE_CONFIG_INIT(&manualQueueConfig, WdfIoQueueDispatchManual);
	manualQueueConfig.PowerManaged = WdfFalse;
	status = WdfIoQueueCreate(wdfDevice, &manualQueueConfig, WDF_NO_OBJECT_ATTRIBUTES, &usbContext->VideoQueue);
	if (!NT_SUCCESS(status)) {
		DbgPrint("Default queue creation failed %d", status);
		goto exit;
	}

One type of request arrive to defaultQueue I will then forward to VideoQueue
if (IoControlCode == IOCTL_VIDEO_DATA_PUSH)
{
//PRINTLINE(“IOCTL_VIDEO_DATA_PUSH”);
status = WdfRequestForwardToIoQueue(Request, usbContext->VideoQueue);
if (NT_SUCCESS(status)) {
//complete I/O later on
return;
}
PRINTLINE(“IOCTL_VIDEO_DATA_PUSH failed”);
WdfRequestComplete(Request, status);
return;
}

Then I use a wdftimer to check the videoQueue every 2 mili seconds
in the timer’s callback function I check the videoqueue

                state = WdfIoQueueGetState(usbContext->VideoQueue, &QueueRequests, &DriverRequests);
		//DbgPrint("state:%d,QueueRequests:%d\n", state & WdfIoQueueNoRequests, QueueRequests);
		if (!(state & WdfIoQueueNoRequests))
		{
			//WDFREQUEST request;
			PVOID inBuf = NULL;

			status = WdfIoQueueRetrieveNextRequest(usbContext->VideoQueue, &usbContext->currentVideoRequest);
			if (!NT_SUCCESS(status)) {
				//discard
				PRINTLINE("Get video request failed");
				WdfRequestComplete(usbContext->currentVideoRequest, STATUS_INVALID_BUFFER_SIZE);
				return status;
			}
              }

I found that if I didn’t call WdfIoQueueGetState first, the system(win10 32/64) will always freez

There is nothing in there that should freeze. Have you hooked up a debugger to see what the system is doing?

However, checking the queue with a 2ms timer is just silly. If you need to handle the request immediately, then just handle it in the original ioctl handler. If you need to serialize the requests, then use a serial queue instead of a manual queue. Then, the callback will get called every time you put something in the queue.

Hi Tim
Thanks for your help
Have you hooked up a debugger to see what the system is doing?--------I will check later
The reason I use timer is becasue I am emulating a virtual cam and I need to transfer the data to host at least every 2 ms

Does WdfIoQueueGetState must be called before WdfIoQueueRetrieveNextRequest on a manual queue?

Answer: No.

Peter