Fixed tests and improve multithread sync
This commit is contained in:
@@ -85,7 +85,7 @@ set(HDRS)
|
||||
set(PHDRS)
|
||||
|
||||
if (TESTS)
|
||||
set(PIP_SRC_CONCURRENT_TEST "src_concurrent/test")
|
||||
set(PIP_SRC_CONCURRENT_TEST "lib/concurrent/test")
|
||||
endif()
|
||||
|
||||
if (DEFINED ENV{QNX_HOST} OR PIP_FREERTOS)
|
||||
|
||||
@@ -64,7 +64,7 @@ void PIThreadPoolExecutor::execute(const std::function<void()> &runnable) {
|
||||
}
|
||||
|
||||
|
||||
volatile bool PIThreadPoolExecutor::isShutdown() const {
|
||||
bool PIThreadPoolExecutor::isShutdown() const {
|
||||
return isShutdown_;
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ TEST_F(ConditionVariable, DISABLED_waitFor_is_block_before_timeout) {
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, waitFor_is_unblock_when_timeout) {
|
||||
volatile bool isUnblock = false;
|
||||
std::atomic_bool isUnblock(false);
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
variable->waitFor(m, WAIT_THREAD_TIME_MS);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define AWRCANFLASHER_TESTUTIL_H
|
||||
|
||||
#include "pithread.h"
|
||||
#include <atomic>
|
||||
|
||||
/**
|
||||
* Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests
|
||||
@@ -16,9 +17,11 @@ PIOBJECT(TestUtil)
|
||||
public:
|
||||
double threadStartTime;
|
||||
PIThread* thread = new PIThread();
|
||||
volatile bool isRunning = false;
|
||||
std::atomic_bool isRunning;
|
||||
std::function<void()> adapterFunctionDefault;
|
||||
|
||||
TestUtil() : isRunning(false) {}
|
||||
|
||||
bool createThread(const std::function<void()>& fun = nullptr, PIThread* thread_ = nullptr) {
|
||||
std::function<void()> actualFun = fun == nullptr ? adapterFunctionDefault : fun;
|
||||
if (thread_ == nullptr) thread_ = thread;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define PIP_TESTS_EXECUTOR_H
|
||||
|
||||
#include "piblockingdequeue.h"
|
||||
#include <atomic>
|
||||
|
||||
/**
|
||||
* @brief Thread pools address two different problems: they usually provide improved performance when executing large
|
||||
@@ -51,11 +52,11 @@ public:
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
volatile bool isShutdown() const;
|
||||
bool isShutdown() const;
|
||||
|
||||
bool awaitTermination(int timeoutMs);
|
||||
private:
|
||||
volatile bool isShutdown_;
|
||||
std::atomic_bool isShutdown_;
|
||||
PIBlockingDequeue<std::function<void()> >* taskQueue;
|
||||
PIVector<PIThread*> threadPool;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user