Re: using grand central dispatch with c++ for inter-thread communication
Re: using grand central dispatch with c++ for inter-thread communication
- Subject: Re: using grand central dispatch with c++ for inter-thread communication
- From: "Daniel A. Steffen" <email@hidden>
- Date: Wed, 21 Apr 2010 12:57:23 -0700
Hi Joel,
On Apr 21, 2010, at 12:05 PM, Joel Reymont wrote:
> I looked at using dispatch queues at first but got stuck. This may be just the opportunity to get me over the stumbling block! This is the crucial bit of code that I can't figure out how to translate to dispatch queues:
>
> static IONotificationPortRef __NotifyPort;
>
> // add notification port and run loop source for async notifications
>
> __NotifyPort = IONotificationPortCreate(masterPort);
> runLoopSource = IONotificationPortGetRunLoopSource(__NotifyPort);
> __MeasatRunLoop = CFRunLoopGetCurrent(),
> CFRunLoopAddSource(__MeasatRunLoop, runLoopSource, kCFRunLoopDefaultMode);
instead of these three lines instead, all that should be needed is
IONotificationPortSetDispatchQueue(__NotifyPort, some_queue)
with some_queue the dispatch queue on which you want IOKit to invoke your callbacks
> // set up notification to detect plugging of Measat without firmware
>
> kr = IOServiceAddMatchingNotification( __NotifyPort,
> kIOFirstMatchNotification,
> matchingDict,
> RawDeviceAdded,
> NULL,
> &__RawAddedIter );
>
> I see dispatch_source_create as a candidate to replace CFRunLoopAddSource but what dispatch source type should I use? There's one for Mach receive and one for Mach send. Which one should I use with the Mach port behind the IO Notification Port? I'm assuming here that I need to get hold of the underlying Mach port.
IONotificationPortSetDispatchQueue() will set up a MACH_RECV dispatch source and handles mach message reception & decoding for you.
You would have to do this yourself if you were to setup your own DISPATCH_SOURCE_TYPE_MACH_RECV source on the port returned by IONotificationPortGetMachPort() (which is probably not even possible with the messages sent by IOKit), a MACH_RECV dispatch source only notifies you when messages are available on the port, it does not receive or decode them.
Cheers,
Daniel _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden