Re: Mutex
- From: mirage2k2 <mirage2k2@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 1 Oct 2007 18:13:00 -0700
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
- Follow-Ups:
- Re: Mutex
- From: Alexander Grigoriev
- Re: Mutex
- Prev by Date: Printer INF for htmldrv
- Next by Date: Re: C++ in KMDF
- Previous by thread: Printer INF for htmldrv
- Next by thread: Re: Mutex
- Index(es):
Relevant Pages
|