crl_dispatch_async.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include <crl/dispatch/crl_dispatch_async.h>
  8. #ifdef CRL_USE_DISPATCH
  9. #include <dispatch/dispatch.h>
  10. namespace crl::details {
  11. void empty_main_wrapper(void (*callable)(void*), void *argument) {
  12. callable(argument);
  13. }
  14. main_queue_wrapper _main_wrapper = &empty_main_wrapper;
  15. void *background_queue_dispatch() {
  16. return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  17. }
  18. void *main_queue_dispatch() {
  19. return dispatch_get_main_queue();
  20. }
  21. void on_queue_async(void *queue, void (*callable)(void*), void *argument) {
  22. dispatch_async_f(
  23. static_cast<dispatch_queue_t>(queue),
  24. argument,
  25. callable);
  26. }
  27. void on_queue_sync(void *queue, void (*callable)(void*), void *argument) {
  28. dispatch_sync_f(
  29. static_cast<dispatch_queue_t>(queue),
  30. argument,
  31. callable);
  32. }
  33. } // namespace crl::details
  34. #endif // CRL_USE_DISPATCH