Re: grand central dispatch and notification port sources
Re: grand central dispatch and notification port sources
- Subject: Re: grand central dispatch and notification port sources
- From: Damien Sorresso <email@hidden>
- Date: Wed, 10 Mar 2010 14:55:49 -0800
On Mar 10, 2010, at 2:34 PM, Joel Reymont wrote:
> Is it possible to add a notification port as a source in Grand Central Dispatch?
>
> I'm looking to replace these three lines of code:
>
> gNotifyPort = IONotificationPortCreate(masterPort);
> runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort);
> CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
>
> GCD has DISPATCH_SOURCE_TYPE_MACH_RECV and DISPATCH_SOURCE_TYPE_MACH_SEND source types that I can pass to dispatch_source_create(). Can I just pass the notification port as a handle?
You could use DISPATCH_SOURCE_TYPE_MACH_RECV, but you'd end up being too clever for your own good. The fact that IOKit's notification ports are Mach ports isn't guaranteed in any API, as far as I know. Also, it'd be up to you to process the message sent to the port and invoke your callback routine. The structure of the messages sent from IOKit to userspace clients is definitely not public.
There is no DISPATCH_SOURCE_TYPE_MACH_SEND. There is DISPATCH_SOURCE_TYPE_MACH_SEND_DEAD, which is a different kettle of fish from a "send-possible" dispatch source.
--
Damien Sorresso
BSD Engineering
Apple Inc.
_______________________________________________
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