crl_common_queue.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/crl_queue.h>
  8. #ifdef CRL_USE_COMMON_QUEUE
  9. #include <crl/crl_async.h>
  10. #include <crl/crl_fp_exceptions.h>
  11. namespace crl {
  12. queue::queue() = default;
  13. queue::queue(main_queue_processor processor) : _main_processor(processor) {
  14. }
  15. void queue::wake_async() {
  16. if (!_queued.test_and_set()) {
  17. (_main_processor ? _main_processor : details::async_plain)(
  18. ProcessCallback,
  19. static_cast<void*>(this));
  20. }
  21. }
  22. void queue::process() {
  23. if (!_list.process()) {
  24. return;
  25. }
  26. _queued.clear();
  27. if (!_list.empty()) {
  28. wake_async();
  29. }
  30. }
  31. void queue::ProcessCallback(void *that) {
  32. #ifdef CRL_THROW_FP_EXCEPTIONS
  33. static thread_local const bool kInited = [] {
  34. toggle_fp_exceptions(true);
  35. return true;
  36. }();
  37. #endif // CRL_THROW_FP_EXCEPTIONS
  38. static_cast<queue*>(that)->process();
  39. }
  40. } // namespace crl
  41. #endif // CRL_USE_COMMON_QUEUE