Skip to content

Add support for CFRunLoop integration APIs #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

seabaylea
Copy link
Contributor

Work has already been done by @kovpas and merged by @parkera to add a CFRunLoop implementation for Linux into CoreFoundation by PR #133 (swiftlang/swift-corelibs-foundation#133).

This followed the model in CFLite of using eventfd rather than mach ports, and calling the following two (new) APIs:

dispatch_get_main_queue_eventfd_np
dispatch_main_queue_drain_np

instead of the existing "4CF" calls:

_dispatch_get_main_queue_port_4CF
_dispatch_main_queue_callback_4CF

Those APIs don't exist in libdispatch, so this adds them. The APIs are defined in queue.h which effectively makes then public - that's been done because it matched the approach used by the CoreFoundation PR. If it makes sense to make them "4CF" functions I can modify the PR here and open an equivalent against CoreFoundation.


// 6618342 Contact the team that owns the Instrument DTrace probe before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ok to remove a comment that says something quite explicit about it not being removed ever.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just moved up a few lines.

@MadCoder
Copy link
Contributor

MadCoder commented Feb 8, 2016

I disagree with that patch, I think it should not add new interfaces for the sake of linux when the _4CF things are just fine. If you diverge too much from the Mac OS X model you will have pain keeping in sync with our changes that keep iterating on how these interfaces work.

@@ -23,6 +23,11 @@
#include "protocol.h"
#endif

#if __linux__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be in "internal.h" and #ifdef

@MadCoder
Copy link
Contributor

MadCoder commented Feb 8, 2016

For the sake of porting I think the right way is like I said, have:

  1. proper guards (suggested DISPATCH_ENABLE_RUNLOOP_SUPPORT)
  2. same function names _4CF, which is not a lie, it's really about giving support to CFRunloop
  3. abstract internally the "port" and its use away but do not touch _dispatch_main_queue_wakeup, only what it calls. The structure should completely be the same.

@seabaylea
Copy link
Contributor Author

I'm happy to rename the guards and move to implementing _4CF functions.

As per my initial comment, I took the approach of implementing the interface functions as dispatch_get_main_queue_eventfd_np and dispatch_main_queue_drain_np because CoreFoundation/RunLoop.subproj/CFRunLoop.c had already been updated to use them.

Presumably we'll new some new _4CF functions for Linux as the consuming CFRunLoop code (currently) needs to know its receiving back a eventfd file descriptor rather than a "port".

@seabaylea
Copy link
Contributor Author

@MadCoder I've made an interaction of changes that moves towards what your looking for - they're not complete but I'd like to get some feedback before doing much more.

For the CFRunLoop entry points, I've retained retained Linux specific APIs, but moved the declaration to queue_internal.h and renamed them as follows:

int dispatch_get_main_queue_eventfd_4CF()
void _dispatch_main_queue_drain_4CF()

The equivalents for Darwin and Windows return a "port"/Handle, and the "drain" function for Darwin has the port as a parameter. Using shared _4CF functions could be achieved but would require a sizeable refactoring of the interface between CFRunLoop and libdispatch. CFRunLoop currently handles the fact that it it working with a port/Handle/eventfd for notifications whereas that would all have to be pushed down to libdispatch.
Does this seem reasonable for now? Should the definitions be moved from queue_internal.h to private.h?

I've introduced a new DISPATCH_ENABLE_RUNLOOP_SUPPORT guard, but had to retain the use of DISPATCH_COCOA_COMPAT and DISPATCH_LINUX_COMPAT for the Darwin/Windows and Linux specific sections. I'm not sure if this is the best approach - and feedback is appreciated.

I've also left the implementation of pthread_main_np as-is for the moment, as that's dependent on PR #44 which isn't yet merged.

@seabaylea
Copy link
Contributor Author

Hi @MadCoder . Can you take a second look at this and give some recommendations on how we can move forward?

@seabaylea
Copy link
Contributor Author

Hi @MadCoder . Have you been able to do another review of this yet?

@MadCoder
Copy link
Contributor

MadCoder commented Jul 7, 2016

Replaced by #101

@MadCoder MadCoder closed this Jul 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants