0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

#0 [Gui] Mac build fix

This commit is contained in:
Victor Zarubkin 2018-03-02 21:08:53 +03:00
parent 3280e951fd
commit 2643ea9b09

View File

@ -62,16 +62,18 @@
# ifdef __MINGW32__ # ifdef __MINGW32__
# include <processthreadsapi.h> # include <processthreadsapi.h>
# endif # endif
#else #elif !defined(__APPLE__)
// For including pthread_setschedprio() // For including pthread_setschedprio()
# include <pthread.h> # include <pthread.h>
#else
# pragma message "TODO: include proper headers to be able to use pthread_setschedprio() on OSX and iOS (pthread.h is not enough...)"
#endif #endif
void setLowestThreadPriority() void setLowestThreadPriority()
{ {
#ifdef _WIN32 #ifdef _WIN32
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
#else #elif !defined(__APPLE__)
pthread_attr_t attr; pthread_attr_t attr;
if (pthread_attr_init(&attr) == 0) if (pthread_attr_init(&attr) == 0)
{ {
@ -80,6 +82,8 @@ void setLowestThreadPriority()
pthread_setschedprio(pthread_self(), sched_get_priority_min(policy)); pthread_setschedprio(pthread_self(), sched_get_priority_min(policy));
pthread_attr_destroy(&attr); 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 #endif
} }
@ -151,11 +155,11 @@ void ThreadPool::tasksWorker()
std::unique_lock<std::mutex> lock(m_tasks.mutex); std::unique_lock<std::mutex> lock(m_tasks.mutex);
m_tasks.cv.wait(lock, [this] { return !m_tasks.queue.empty() || m_interrupt.load(std::memory_order_acquire); }); 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 while (true) // execute all available tasks
{ {
if (m_interrupt.load(std::memory_order_acquire))
return;
if (m_tasks.queue.empty()) if (m_tasks.queue.empty())
break; // the lock will be released on the outer loop new iteration 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); return !m_backgroundJobs.queue.empty() || m_interrupt.load(std::memory_order_acquire);
}); });
if (m_interrupt.load(std::memory_order_acquire)) while (true) // execute all available jobs
break;
while (true) // execute all available tasks
{ {
if (m_interrupt.load(std::memory_order_acquire))
return;
if (m_backgroundJobs.queue.empty()) if (m_backgroundJobs.queue.empty())
break; // the lock will be released on the outer loop new iteration break; // the lock will be released on the outer loop new iteration