fix thread sanitizer warnings

This commit is contained in:
lganzzzo 2019-10-31 03:17:59 +02:00
parent 8ef446527f
commit c9aeb9337f
5 changed files with 13 additions and 40 deletions

View File

@ -86,7 +86,7 @@ public:
) {
auto startTime = std::chrono::system_clock::now();
bool running = true;
std::atomic<bool> running(true);
std::mutex timeoutMutex;
std::condition_variable timeoutCondition;

View File

@ -51,7 +51,7 @@ private:
private:
oatpp::async::Processor m_processor;
private:
bool m_isRunning;
std::atomic<bool> m_isRunning;
private:
std::thread m_thread;
public:

View File

@ -158,44 +158,16 @@ void Processor::consumeAllTasks() {
void Processor::pushQueues() {
static constexpr v_int32 MAX_BATCH_SIZE = 1000;
oatpp::collection::FastQueue<CoroutineHandle> tmpList;
if(!m_taskList.empty()) {
if (m_taskList.size() < MAX_BATCH_SIZE && m_queue.first != nullptr) {
std::unique_lock<oatpp::concurrency::SpinLock> lock(m_taskLock, std::try_to_lock);
if (lock.owns_lock()) {
consumeAllTasks();
}
} else {
std::lock_guard<oatpp::concurrency::SpinLock> lock(m_taskLock);
consumeAllTasks();
}
{
std::lock_guard<oatpp::concurrency::SpinLock> lock(m_taskLock);
consumeAllTasks();
oatpp::collection::FastQueue<CoroutineHandle>::moveAll(m_pushList, tmpList);
}
if(m_pushList.first != nullptr) {
if (m_pushList.count < MAX_BATCH_SIZE && m_queue.first != nullptr) {
std::unique_lock<oatpp::concurrency::SpinLock> lock(m_taskLock, std::try_to_lock);
if (lock.owns_lock()) {
oatpp::collection::FastQueue<CoroutineHandle> tmpList;
oatpp::collection::FastQueue<CoroutineHandle>::moveAll(m_pushList, tmpList);
lock.unlock();
while(tmpList.first != nullptr) {
addCoroutine(tmpList.popFront());
}
}
} else {
oatpp::collection::FastQueue<CoroutineHandle> tmpList;
{
std::lock_guard<oatpp::concurrency::SpinLock> lock(m_taskLock);
oatpp::collection::FastQueue<CoroutineHandle>::moveAll(m_pushList, tmpList);
}
while(tmpList.first != nullptr) {
addCoroutine(tmpList.popFront());
}
}
while(tmpList.first != nullptr) {
addCoroutine(tmpList.popFront());
}
}
@ -248,7 +220,8 @@ bool Processor::iterate(v_int32 numIterations) {
end_loop:
popTasks();
std::lock_guard<oatpp::concurrency::SpinLock> lock(m_taskLock);
return m_queue.first != nullptr || m_pushList.first != nullptr || !m_taskList.empty();
}

View File

@ -74,7 +74,7 @@ private:
private:
IOEventWorkerForeman* m_foreman;
Action::IOEventType m_specialization;
bool m_running;
std::atomic<bool> m_running;
oatpp::collection::FastQueue<CoroutineHandle> m_backlog;
oatpp::concurrency::SpinLock m_backlogLock;
private:

View File

@ -41,7 +41,7 @@ namespace oatpp { namespace async { namespace worker {
*/
class TimerWorker : public Worker {
private:
bool m_running;
std::atomic<bool> m_running;
oatpp::collection::FastQueue<CoroutineHandle> m_backlog;
oatpp::collection::FastQueue<CoroutineHandle> m_queue;
oatpp::concurrency::SpinLock m_backlogLock;