Re: Mutex

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



As long as you are waiting at IRQL < DISPATCH_LEVEL ... just wait on an event
object that the ISR sets when it runs - you may want to use autoresetting
event.

You could also get your ISR to queue a work item, when you do this the
system will call your work item handler function later at IRQL ==
PASSIVE_LEVEL ... use the following code ...

typedef struct strQueuedWorkItem
{
PIO_WORKITEM IOWorkItem;
void *data;

} QueuedWorkItem;

static void dequeueHandler(PDEVICE_OBJECT deviceObject, PVOID context);


// queue function ...
//
void queueWorkItem(PDEVICE_OBJECT deviceObject, void *data)
{
QueuedWorkItem *queuedWorkItem;

queuedWorkItem = ExAllocatePool(NonPagedPool, sizeof(QueuedWorkItem));
if (queuedWorkItem)
{
PIO_WORKITEM IOWorkItem = IoAllocateWorkItem(deviceObject);
if (IOWorkItem)
{
queuedWorkItem->IOWorkItem = IOWorkItem;
queuedWorkItem->data = data;
IoQueueWorkItem(IOWorkItem, dequeueHandler, CriticalWorkQueue,
queuedWorkItem);
}
}
}

// dequeue handler ...
//
void dequeueHandler(PDEVICE_OBJECT deviceObject, PVOID context)
{
QueuedWorkItem *queuedWorkItem = (QueuedWorkItem *)context;
void *data = queuedWorkItem->data;
// ...
// DO SOMETHING HERE
// ...
IoFreeWorkItem(queuedWorkItem->IOWorkItem);
}

.... in your ISR ...

queueWorkItem(deviceObject, data);


I am guessing that you want something done when the ISR runs but you don't
want it running in the context of your ISR. The queue work item code above
should work fine but there may be a better solution ... look at DDK help for
ISRs.

Mirage2k2.

"Hasitha" wrote:

Thankx Varenni
Do you mean Interrupt Service Routine?
You cannot call KeReleaseMutex in your ISR, KeReleaseMutex (as almost all
the other routines working on wait objects) cannot be called at IRQL >
DISPATCH_LEVEL.

I juest want to wait untill ISR call. what would be the better way for it.

"Gianluca Varenni" wrote:


"Hasitha" <Hasitha@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ACAB6067-6853-49D5-827A-EF4FA2036130@xxxxxxxxxxxxxxxx
Hi all,
Thank you very much in advance.

I try to use Mutex in my driver program and it does not work as i expect.
I am try to develop driver to PCi device.

In write function write data to dma data buffer and start DAM and lock
mutex.
When dma finish his job hi will call interrupt callback function. callback
function will unlock the Meutex.

In init function
KeInitializeMutex(&(pDevEex->Mutex),0);


in Write function

WriteDataToDMA();
StartDMA();
while(1)
{
if((NtStatus = KeWaitForMutexObject(&(pDevEex->Mutex), Executive,
KernelMode, FALSE, NULL)==STATUS_SUCCESS){
break;

}
}


In Interrupt callback function
if(!KeReadStateMutex(&(pDevEex->Mutex)))
KeReleaseMutex(&(pDevEex->Mutex),FALSE);


Do you mean Interrupt Service Routine?
You cannot call KeReleaseMutex in your ISR, KeReleaseMutex (as almost all
the other routines working on wait objects) cannot be called at IRQL >
DISPATCH_LEVEL.

What are you trying to accomplish with your design? Acquiring a mutex in a
routine and releasing it in the ISR seems a very very bad idea.

Have a nice day
GV


--
Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com





The problem is function do not wait in KeWaitForMutexObject() function and
program loop in while loop.

What wold be the reason for it.
your corporation is highly appreciated.

With Best Regards

Hasitha



.



Relevant Pages

  • Re: Mutex
    ... So looking at the DDK help, work is done in another context using ... You could also get your ISR to queue a work item, ... static void dequeueHandler; ... QueuedWorkItem *queuedWorkItem; ...
    (microsoft.public.development.device.drivers)
  • Re: process + interrupt handler question
    ... Actually the docs specifically state that PsGetCurrentProcess can be running ... at any IRQL, but calling it within an ISR is a bit oxymoronic since DIRQL ... > See DDK documentation ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Mutex
    ... I've never written an ISR ... ... So looking at the DDK help, work is done in another context using ... static void dequeueHandler; ... QueuedWorkItem *queuedWorkItem; ...
    (microsoft.public.development.device.drivers)
  • Re: Mutex
    ... An ISR CAN NOT set an event, CAN NOT call ExAllocatePool, CAN NOT call ... static void dequeueHandler; ... QueuedWorkItem *queuedWorkItem; ... the other routines working on wait objects) cannot be called at IRQL> ...
    (microsoft.public.development.device.drivers)
  • RE: DPC/ISR synchronization (windows ce)
    ... the ISR was two priority levels above the ... >> Does the DPC raise IRQL, and if so what does it raise it to? ... >>> interrupt and setting the interrupt event in time with the hardware, ...
    (microsoft.public.development.device.drivers)