site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Hi Herb, As per your suggestion I have tried using IOLockSleep() in my driver code to put the current running thread in wait. But when these API gets called my driver crashes. The Code snippet for the same is as follow: void* com_My_driver::handle_request_loop(void *data) { com_My_driver* objDriver; WriteBuffReq* a_request; /* pointer to a request.*/ a_request = new WriteBuffReq[sizeof(WriteBuffReq)]; int thread_id = *((int*) data); /* thread identifying number */ request_mutex = IOLockAlloc(); /* lock the mutex, to access the requests list exclusively. */ IOLockLock(request_mutex); /* do forever... */ while (1) { if(num_requests > 0) /* a request is pending */ { a_request = objDriver->get_request(request_mutex); // get the write request node from the linklist if(a_request) /* got a request - handle it and free it */ { IOLockUnlock(request_mutex); objDriver->handle_request(a_request, thread_id); // handle the incoming write request delete[] a_request; /* and lock the mutex again. */ IOLockLock(request_mutex); } /* if(a_request) */ } /* if(num_requests > 0) */ else { /* wait for a request to arrive. note the mutex will be */ /* unlocked here, thus allowing other threads access to */ /* requests list. */ IOLog("handle_request_loop():: thread '%d' before IOLockSleep\n", thread_id); IOLockSleep(request_mutex, (void*) thread_id, 0); // Driver Crashing Here /* and after we return from IOLockSleep, the mutex */ /* is locked again */ } /* else */ } /* while */ } Is that I am doing something wrong in using these API's ?? Looking for your valuable suggestions. Thanks & Regards, Yogesh Pahilwan On Fri, 2005-12-09 at 00:04, Herb Petschauer wrote:
No worries, the less confusion that my addled brain is exposed to, the better...
Have you looked at IOLockSleep()? Same header file as IOLockLock().
Depending on what kind of driver you are implementing you may want to search the docs and the list archives (and developer.apple.com) for "primary interrupt" and "secondary interrupt".
Cheers, H.
On 08 Dec 2005 18:31:02 +0530, Yogesh P <pahilwan.yogesh@spsoftindia.com> wrote:
Hi Herb,
Sorry Herb.
Now I am replying to the old thread.
I am actually implementing a threading and synchronization mechanism for accessing a request queue which is a queue of write data structure having singly linklist.
I am creating kernel threads in my init() driver function. These threads access the request queue paralelly by using IOKit's IOLock synchronization primitives.
Each thread acquire the lock calling IOLockLock() function and check the request queue whether it is empty or not. If the request queue is empty then the thread release the lock by calling IOLockUnLock() function. So that other threads can access the request queue.
After loading the driver, threads get created successfully and each thread goes in a big while loop and the loop goes on infinitely.
Now I have to put each thread on a conditional wait. The conditional wait means that if there is no request in the request queue the thread delays for a nanosecond and release the lock from the request queue for that specified time delay, and as soon as the request comes in the request queue, thread wake ups, acquire the lock and process that specified request.
Is there any mechanism in IOKit so that I can put the thread on conditional wait ?? After that condition met, wake up that thread to process the specified request ??
Thanks in advance, Yogesh Pahilwan
On Wed, 2005-12-07 at 22:01, Herb Petschauer wrote:
Again, this email seems to be a new thread. Why not just reply to the old thread?
Anway: http://developer.apple.com/documentation/Darwin/Conceptual/KernelProgramming...
You will find the entire document enlightening actually :-)
H.
On 07 Dec 2005 18:22:18 +0530, Yogesh P <pahilwan.yogesh@spsoftindia.com> wrote:
Hi Herb,
Thanks for your valuable suggestion about the threading and synchronization in Mac OS X.
I am also thankful to Garth for his suggestions.
Now my driver is not getting crash when I call the IOCreateThread() function.
Is there any API to put the kernel thread in a wait for a nanosecond in sleep in IOKit??
Thanks, Yogesh
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/bogvardi%40gmail.com
This email sent to bogvardi@gmail.com
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com