-
Notifications
You must be signed in to change notification settings - Fork 15
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
libdispatch++ on Mac OS X with vanilla libdispatch #2
Comments
Huh, it sucks that there's no lambdas. I take it that's the case for both clang and g++?
Ultimately, I'd like to ensure that my entire libdispatch builds correctly on Mac OS X and functions properly as a drop-in replacement for the system library. |
Also it's worth pointing out that without lambdas it's much less compelling, and you may be better off with the function pointer/ |
Yeah, Apple won't ship a version of GCC new enough to have lambdas because they're all GPLv3. Clang will probably have them in a few months though. Which will be good because lambdas definitely are a necessary part of a compelling GCD API.
|
here's a patch containing all my changes to make it compile. I would just push my changes to my fork but this is a second GitHub account and GitHub doesn't allow more than one user to have the same public key. If I make any actual worthwhile changes I'll have to mess with it and make it work.
|
Well, I can understand avoiding GPLv3. Nonetheless, a little aggravating. Hopefully clang can catch up, and allow operating systems of various flavours to escape gcc's generally awful design.
Re: your diff, I actually made a bunch of modifications last night that obsoletes some of those changes, but I'll take the bits that are still relevant. |
turns out the dispatch_get_main_queue() macro isn't shadowing a function at all: and now I've pushed my changes to my fork |
If you just declare |
No, the linker reports it as an undefined symbol. |
I saw the first time ;) Oh, I guess it also needs to be extern "C". If it still can't find it, that is rather annoying. Especially as I couldn't even get the macro to work; for some reason VC++ gave weird linker errors that didn't seem entirely appropriate, so I'm forced to put a proper declaration in the header. |
Ah, I should have seen that myself. extern "C" does indeed work. |
The thing that bothers me about it is it matters what thread it's called on. dispatch_get_main_queue() works for Cocoa because Cocoa requires all GUI updates to be on the same thread, so you can get the right queue from anywhere. I think this is nicer, if it can actually be implmented: |
Well, I agree that that would be a bit nicer, but there's no clear way to me to implement it from libdispatch's side of the fence. libdispatch doesn't know when HWNDs get conjured into existence, and thread queues are stored in TLS, so there's no easy way to get at them from outside the thread. They're also allocated only lazily; if a thread never touches its queue, it never gets created in the first place. So, I think a satisfactory approach would be this: https://gist.github.com/1045683 In other words, leave it up to client code to keep its mapping of "arbitrary thing" (in this case, HWND) to dispatch_queue_t. Now, naively one might say that you could do the same for a mapping from thread_id to queue too. It would probably be possible, but it would require more extensive changes in order to achieve the same affinitized queue draining behaviour. |
Intel TBB has a concurrent_hash_map that has safe concurrent insert and delete, so would be suitable for such a mapping. |
Just a note that your current version (1ed626c) of dispatch.cpp is still compiling without modification as of OS X 10.7.1 (11B26) In case you didn't see and do care, the Lion modifications to libdispatch were released a little while ago and the maintainers were talking about taking changes before they merged Lion's modifications in. |
Yeah, I know they've made a load of changes. I'm a bit scared of looking at it all, to be honest; I fear that quite a lot of it will be a pain in the ass to port. |
(courtesy of bames53 on the Ars forums: http://arstechnica.com/civis/viewtopic.php?p=21780264#p21780264)
I'm building with
clang++ -stdlib=libc++ -std=c++0x -Wall dispatch.cpp -c
usingclang version 3.0 (http://llvm.org/git/clang.git b10a13b1e2c34732d13b84494bb0a13a5822f945)
and Target:x86_64-apple-darwin10.7.0
(which unfortunately does not yet support lambdas)extern
causes an error in the following#define
. Same when I use Apple's gcc.typedef dispatch_function_apply_t
doesn't exist in the libdispatch headers on OS X 10.6.dispatch_once
,dispatch_once_f
, anddispatch_get_main_queue
are implemented as macros, so prefixing them with::
to access the symbols in the global namespace fails.dispatch_once
is a macro so defining a function of the same name inside a namespace fails, as does trying to call that function.dispatch_atomic_*
are not part of the public interface to libdispatch and so they're not in the headers. To get around this I copy/pasted the definition from atomic.h in your src tree for the onedispatch_atomic_*
function that's used in dispatch.cpp.dispatch_get_current_thread_queue()
is not protected by#ifdefs
#ifdef
s: Windows.h, SDKDDKVer.h,::DebugBreak()
ON_BLOCK_EXIT
)After these were fixed or worked around it was enough to get a couple simple programs to run:
Compiled with
clang++ -stdlib=libc++ -std=c++0x -Wall dispatch.cpp main.cpp
Ugh, for some reason the github markdown is breaking the list numbering.
The text was updated successfully, but these errors were encountered: