Skip to content

libdispatch++ on Mac OS X with vanilla libdispatch #2

@DrPizza

Description

@DrPizza

(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 using clang 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)

  1. The extern causes an error in the following #define. Same when I use Apple's gcc.
    #define DISPATCHPP_EXPORT extern __attribute__((visibility("default")))
  1. the typedef dispatch_function_apply_t doesn't exist in the libdispatch headers on OS X 10.6.
  2. dispatch_once, dispatch_once_f, and dispatch_get_main_queue are implemented as macros, so prefixing them with :: to access the symbols in the global namespace fails.
  3. dispatch_once is a macro so defining a function of the same name inside a namespace fails, as does trying to call that function.
  4. The 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 one dispatch_atomic_* function that's used in dispatch.cpp.
  5. use of libdispatch extension dispatch_get_current_thread_queue() is not protected by #ifdefs
  6. some Windows stuff not protected by #ifdefs: Windows.h, SDKDDKVer.h, ::DebugBreak()
  7. Due to lack of compiler support I replaced the use of lambda's with a function object. (ON_BLOCK_EXIT)

After these were fixed or worked around it was enough to get a couple simple programs to run:

void foo(size_t i) {
   printf("Hello %zu\n",i);
}

int main(int argc,char *argv[]) {
   gcd::queue::get_global_queue(0,0).apply(10,std::function<void(size_t)>(foo));
   return 0;
}

Code:
void foo(void) {
   printf("Hello");
}
void bar(void) {
   exit(0);
}

int main(int argc,char *argv[]) {
   gcd::queue::get_main_queue().async(std::function<void()>(foo));
   gcd::queue::get_main_queue().async(std::function<void()>(bar));
   dispatch_main();
   return 0;
}

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions