PIThreadPoolExecutor & PIBlockingDequeue improvements
- add support move & copy semantic - introduce submit method for executor with future result
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "pithread.h"
|
||||
#include "testutil.h"
|
||||
|
||||
class ConditionVariable : public ::testing::Test, public TestUtil {
|
||||
class ConditionVariableIntegrationTest : public ::testing::Test, public TestUtil {
|
||||
public:
|
||||
PIMutex m;
|
||||
PIConditionVariable* variable;
|
||||
@@ -19,30 +19,30 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ConditionVariable, wait_is_block) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_is_block) {
|
||||
createThread();
|
||||
ASSERT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_is_block_when_notifyOne_before_wait) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_is_block_when_notifyOne_before_wait) {
|
||||
variable->notifyOne();
|
||||
createThread();
|
||||
ASSERT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_is_block_when_notifyAll_before_wait) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_is_block_when_notifyAll_before_wait) {
|
||||
variable->notifyAll();
|
||||
createThread();
|
||||
ASSERT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_is_unblock_when_notifyOne_after_wait) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_is_unblock_when_notifyOne_after_wait) {
|
||||
createThread();
|
||||
variable->notifyOne();
|
||||
ASSERT_TRUE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_is_unblock_when_notifyAll_after_wait) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_is_unblock_when_notifyAll_after_wait) {
|
||||
PIVector<PIThread*> threads;
|
||||
|
||||
for (int i = 0; i < THREAD_COUNT; ++i) {
|
||||
@@ -61,7 +61,7 @@ TEST_F(ConditionVariable, wait_is_unblock_when_notifyAll_after_wait) {
|
||||
piForeach(PIThread* thread, threads) delete thread;
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_is_one_unblock_when_notifyOne) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_is_one_unblock_when_notifyOne) {
|
||||
PIVector<PIThread*> threads;
|
||||
|
||||
for (int i = 0; i < THREAD_COUNT; ++i) {
|
||||
@@ -77,7 +77,7 @@ TEST_F(ConditionVariable, wait_is_one_unblock_when_notifyOne) {
|
||||
ASSERT_EQ(runningThreadCount, THREAD_COUNT - 1);
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_is_protected_unblock_when_notifyOne) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_is_protected_unblock_when_notifyOne) {
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
variable->wait(m);
|
||||
@@ -89,7 +89,7 @@ TEST_F(ConditionVariable, wait_is_protected_unblock_when_notifyOne) {
|
||||
ASSERT_FALSE(m.tryLock());
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_condition_is_block) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_condition_is_block) {
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
variable->wait(m, [](){ return false; });
|
||||
@@ -98,7 +98,7 @@ TEST_F(ConditionVariable, wait_condition_is_block) {
|
||||
ASSERT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_condition_is_check_condition_before_block) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_condition_is_check_condition_before_block) {
|
||||
bool isConditionChecked = false;
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
@@ -113,7 +113,7 @@ TEST_F(ConditionVariable, wait_condition_is_check_condition_before_block) {
|
||||
m.unlock();
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_condition_is_check_condition_when_notifyOne) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_condition_is_check_condition_when_notifyOne) {
|
||||
bool isConditionChecked;
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
@@ -133,7 +133,7 @@ TEST_F(ConditionVariable, wait_condition_is_check_condition_when_notifyOne) {
|
||||
m.unlock();
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, wait_condition_is_unblock_when_condition_and_notifyOne) {
|
||||
TEST_F(ConditionVariableIntegrationTest, wait_condition_is_unblock_when_condition_and_notifyOne) {
|
||||
bool condition = false;
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
@@ -147,7 +147,7 @@ TEST_F(ConditionVariable, wait_condition_is_unblock_when_condition_and_notifyOne
|
||||
ASSERT_TRUE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, DISABLED_waitFor_is_block_before_timeout) {
|
||||
TEST_F(ConditionVariableIntegrationTest, DISABLED_waitFor_is_block_before_timeout) {
|
||||
createThread([&](){
|
||||
PITimeMeasurer measurer;
|
||||
m.lock();
|
||||
@@ -159,7 +159,7 @@ TEST_F(ConditionVariable, DISABLED_waitFor_is_block_before_timeout) {
|
||||
EXPECT_TRUE(thread->waitForFinish(WAIT_THREAD_TIME_MS * 3));
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, waitFor_is_unblock_when_timeout) {
|
||||
TEST_F(ConditionVariableIntegrationTest, waitFor_is_unblock_when_timeout) {
|
||||
std::atomic_bool isUnblock(false);
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
@@ -172,7 +172,7 @@ TEST_F(ConditionVariable, waitFor_is_unblock_when_timeout) {
|
||||
ASSERT_TRUE(isUnblock);
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, waitFor_is_false_when_timeout) {
|
||||
TEST_F(ConditionVariableIntegrationTest, waitFor_is_false_when_timeout) {
|
||||
bool waitRet = true;
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
@@ -183,7 +183,7 @@ TEST_F(ConditionVariable, waitFor_is_false_when_timeout) {
|
||||
ASSERT_FALSE(waitRet);
|
||||
}
|
||||
|
||||
TEST_F(ConditionVariable, waitFor_is_unblock_when_condition_and_notifyOne) {
|
||||
TEST_F(ConditionVariableIntegrationTest, waitFor_is_unblock_when_condition_and_notifyOne) {
|
||||
bool condition = false;
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
|
||||
Reference in New Issue
Block a user