Re: Mutex
- From: "Alexander Grigoriev" <alegr@xxxxxxxxxxxxx>
- Date: Tue, 2 Oct 2007 06:20:00 -0700
These functions can be called on DISPATCH_LEVEL
"mirage2k2" <mirage2k2@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B497A88A-16B7-4F5B-9CE3-D870A547734A@xxxxxxxxxxxxxxxx
I've never written an ISR ... I should have looked into this before
responding.
So looking at the DDK help, work is done in another context using
IoRequestDpc() and DpcForIsr(). Can your DpcForIsr() function set an
event,
call ExAllocatePool, call IoQueueWorkitem?
Mirage2k2.
"Alexander Grigoriev" wrote:
An ISR CAN NOT set an event, CAN NOT call ExAllocatePool, CAN NOT call
IoQueueWorkitem....
"mirage2k2" <mirage2k2@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:446D5ED9-FF5D-4017-AA35-61B9D3249719@xxxxxxxxxxxxxxxx
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
.
- Prev by Date: Re: KMDF Fakemodem not working
- Next by Date: enumarate list of device driver for sound, video and game controllers
- Previous by thread: Re: Mutex
- Next by thread: Re: KMDF Fakemodem not working
- Index(es):
Relevant Pages
|