Re: Mutex

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




"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: C++ Function Static Initialization, Thread-Safe?
    ... void* thread{ ... that says you cannot take a mutex in the `init' routine. ... It's just a problem of waiting for something ...
    (comp.programming.threads)
  • RE: Mutex
    ... The mutex is initialized in the signalled state so your initial wait will not ... I try to use Mutex in my driver program and it does not work as i expect. ... When dma finish his job hi will call interrupt callback function. ... program loop in while loop. ...
    (microsoft.public.development.device.drivers)
  • Re: [PATCH -mm1 1/2] fixing idr_find() locking
    ... the mutex has been changed into a reader/writer semaphore. ... a new routine ipc_lock_downhas been defined: ... there is one big mistake around To/Cc ordering, so I doubt Andrew ...
    (Linux-Kernel)
  • Re: [PATCH 15/15] Add DEFINE_SPUFS_ATTRIBUTE()
    ... DEFINE_SIMPLE_ATTRIBUTE which does the specified locking for the get ... routine for us. ... Have you looked at the change in object code size? ... require the mutex to be held in the first place. ...
    (Linux-Kernel)
  • RE: Mutex
    ... I normally wait on event objects - the signaled state is changed using ... I have also used fast mutex, they are easy you just call ... When dma finish his job hi will call interrupt callback function. ... program loop in while loop. ...
    (microsoft.public.development.device.drivers)