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