From 2643ea9b09810aa1d53ddaa810fcdc9f25620ae4 Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Fri, 2 Mar 2018 21:08:53 +0300 Subject: [PATCH] #0 [Gui] Mac build fix --- profiler_gui/thread_pool.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/profiler_gui/thread_pool.cpp b/profiler_gui/thread_pool.cpp index 7b605f4..588afbe 100644 --- a/profiler_gui/thread_pool.cpp +++ b/profiler_gui/thread_pool.cpp @@ -62,16 +62,18 @@ # ifdef __MINGW32__ # include # endif -#else +#elif !defined(__APPLE__) // For including pthread_setschedprio() # include +#else +# pragma message "TODO: include proper headers to be able to use pthread_setschedprio() on OSX and iOS (pthread.h is not enough...)" #endif void setLowestThreadPriority() { #ifdef _WIN32 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); -#else +#elif !defined(__APPLE__) pthread_attr_t attr; if (pthread_attr_init(&attr) == 0) { @@ -80,6 +82,8 @@ void setLowestThreadPriority() pthread_setschedprio(pthread_self(), sched_get_priority_min(policy)); pthread_attr_destroy(&attr); } +#else + /// TODO: include proper headers to be able to use pthread_setschedprio() on OSX and iOS (pthread.h is not enough...) #endif } @@ -151,11 +155,11 @@ void ThreadPool::tasksWorker() std::unique_lock lock(m_tasks.mutex); m_tasks.cv.wait(lock, [this] { return !m_tasks.queue.empty() || m_interrupt.load(std::memory_order_acquire); }); - if (m_interrupt.load(std::memory_order_acquire)) - break; - while (true) // execute all available tasks { + if (m_interrupt.load(std::memory_order_acquire)) + return; + if (m_tasks.queue.empty()) break; // the lock will be released on the outer loop new iteration @@ -186,11 +190,11 @@ void ThreadPool::jobsWorker() return !m_backgroundJobs.queue.empty() || m_interrupt.load(std::memory_order_acquire); }); - if (m_interrupt.load(std::memory_order_acquire)) - break; - - while (true) // execute all available tasks + while (true) // execute all available jobs { + if (m_interrupt.load(std::memory_order_acquire)) + return; + if (m_backgroundJobs.queue.empty()) break; // the lock will be released on the outer loop new iteration