On Wednesday, March 5, 2003, at 01:37 PM, Vivek Balasubramanyam wrote: Hi. I'm porting some driver code from Linux, and having trouble using the wait_queue API (in kern/wait_queue.h). I use "wq = wait_queue_alloc(SYNC_POLICY_FIFO);" to set things up, "wait_queue_assert_wait(&wq, NO_EVENT, THREAD_INTERRUPTIBLE)" to add my single thread to the queue, and wakeup_one to wake it up. It looks like my driver is locking the machine in a loop containing the assert_wait() call: while (1) { ..check if there's data ready to be processed.. ..if so, break ..else, assert_wait } The waiting thread is only woken up by me when new data is ready to be processed, and yet execution in this thread never leaves that loop. I haven't been able to find much information on wait_queues. Is there something obvious I'm missing about their initialization or use? What kind of driver are you porting. Usually, higher level synchronization is used in drivers (command gates in IOKit drivers, tsleep is BSD drivers, etc...). The wait_queue mechanism is pretty low-level for drivers. Wait queues alone are not enough to provide the synchronization that the code above needs. You must use some sort of lock to protect the atomicity of the "check if there's data, otherwise assert_wait" operation. Once you have firmly asserted your intention to wait, you can unlock whatever form of lock you chose and then volunteer to give up the CPU (when working at this low a level, that would usually be with thread_block()). It sounds like you aren't giving up the CPU (and therefore would only get taken off the CPU to be preempted by a realtime thread). --Jim _______________________________________________ darwin-kernel mailing list | darwin-kernel@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel Do not post admin requests to the list. They will be ignored.
participants (1)
-
Jim Magee