I am developing a device driver on mac. my question is how can we make a device request asynchronous to synchronous. like i send a send encapsulated command to device and get it response using get encapsulated command after getting a notification on interrupt pipe. so how can i make my thread will wait until all above request is not completed (both send and get) .
相关问题
- How to let a thread communicate with another activ
- Why it isn't advised to call the release() met
- Xcode debugger displays incorrect values for varia
- Is there a way to report errors in Apple documenta
- ThreadPoolTaskScheduler behaviour when pool is ful
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- xcode 4 garbage collection removed?
- Difference between Thread#run and Thread#wakeup?
- IntelliJ IDEA can't open projects or add SDK o
- Java/Spring MVC: provide request context to child
- Automator: How do I use the Choose from List actio
- Xcode: Is there a way to change line spacing (UI L
You'll probably have to be a bit more specific than that. But in general, if you need a thread to sleep until some function of yours is called on another thread, you can use xnu's event system. As this is a device driver, I assume you're using the I/O Kit - in that case, the IO Locks or IOCommandGates are the most appropriate.
Using explicit locks, in your driver instance, you'd have something like:
You'll initialise these somewhere:
Then, when your thread initiates some I/O:
In yourCallbackFunction:
Obviously, if you have multiple simultaneous I/Os going, your status variable will need to be per-context, etc. And in the kernel, asynchronous design is often better than synchronous. But I assume you know all about this kind of general driver design and have weighed up the pros and cons.
The
IOCommandGate
sleep/wake API is very similar and should be used if you're doing thread synchronisation on yourIOWorkLoop
. If you're not using the I/O Kit, you may prefer to use the BSD-level lock/mutex API, which is what the IOLock is implemented on anyway.