mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-05 23:07:42 -05:00
Merge pull request #100770 from hpvb/command-queue-mt
Core: Refactor CommandQueueMT to use vararg templates for performance and maintainability
This commit is contained in:
@@ -201,10 +201,10 @@ public:
|
||||
command_queue.push_and_sync(this, &SharedThreadState::func2, tr, f);
|
||||
break;
|
||||
case TEST_MSGRET_FUNC1_TRANSFORM:
|
||||
command_queue.push_and_ret(this, &SharedThreadState::func1r, tr, &otr);
|
||||
command_queue.push_and_ret(this, &SharedThreadState::func1r, &otr, tr);
|
||||
break;
|
||||
case TEST_MSGRET_FUNC2_TRANSFORM_FLOAT:
|
||||
command_queue.push_and_ret(this, &SharedThreadState::func2r, tr, f, &otr);
|
||||
command_queue.push_and_ret(this, &SharedThreadState::func2r, &otr, tr, f);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -244,6 +244,44 @@ public:
|
||||
}
|
||||
writer_thread.wait_to_finish();
|
||||
}
|
||||
|
||||
struct CopyMoveTestType {
|
||||
inline static int copy_count;
|
||||
inline static int move_count;
|
||||
int value = 0;
|
||||
|
||||
CopyMoveTestType(int p_value = 0) :
|
||||
value(p_value) {}
|
||||
|
||||
CopyMoveTestType(const CopyMoveTestType &p_other) :
|
||||
value(p_other.value) {
|
||||
copy_count++;
|
||||
}
|
||||
|
||||
CopyMoveTestType(CopyMoveTestType &&p_other) :
|
||||
value(p_other.value) {
|
||||
move_count++;
|
||||
}
|
||||
|
||||
CopyMoveTestType &operator=(const CopyMoveTestType &p_other) {
|
||||
value = p_other.value;
|
||||
copy_count++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CopyMoveTestType &operator=(CopyMoveTestType &&p_other) {
|
||||
value = p_other.value;
|
||||
move_count++;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
void copy_move_test_copy(CopyMoveTestType p_test_type) {
|
||||
}
|
||||
void copy_move_test_ref(const CopyMoveTestType &p_test_type) {
|
||||
}
|
||||
void copy_move_test_move(CopyMoveTestType &&p_test_type) {
|
||||
}
|
||||
};
|
||||
|
||||
static void test_command_queue_basic(bool p_use_thread_pool_sync) {
|
||||
@@ -446,6 +484,83 @@ TEST_CASE("[Stress][CommandQueue] Stress test command queue") {
|
||||
ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING,
|
||||
ProjectSettings::get_singleton()->property_get_revert(COMMAND_QUEUE_SETTING));
|
||||
}
|
||||
|
||||
TEST_CASE("[CommandQueue] Test Parameter Passing Semantics") {
|
||||
SharedThreadState sts;
|
||||
sts.init_threads();
|
||||
|
||||
SUBCASE("Testing with lvalue") {
|
||||
SharedThreadState::CopyMoveTestType::copy_count = 0;
|
||||
SharedThreadState::CopyMoveTestType::move_count = 0;
|
||||
|
||||
SharedThreadState::CopyMoveTestType lvalue(42);
|
||||
|
||||
SUBCASE("Pass by copy") {
|
||||
sts.command_queue.push(&sts, &SharedThreadState::copy_move_test_copy, lvalue);
|
||||
|
||||
sts.message_count_to_read = -1;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
|
||||
CHECK(SharedThreadState::CopyMoveTestType::copy_count == 1);
|
||||
CHECK(SharedThreadState::CopyMoveTestType::move_count == 1);
|
||||
}
|
||||
|
||||
SUBCASE("Pass by reference") {
|
||||
sts.command_queue.push(&sts, &SharedThreadState::copy_move_test_ref, lvalue);
|
||||
|
||||
sts.message_count_to_read = -1;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
|
||||
CHECK(SharedThreadState::CopyMoveTestType::copy_count == 1);
|
||||
CHECK(SharedThreadState::CopyMoveTestType::move_count == 0);
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Testing with rvalue") {
|
||||
SharedThreadState::CopyMoveTestType::copy_count = 0;
|
||||
SharedThreadState::CopyMoveTestType::move_count = 0;
|
||||
|
||||
SUBCASE("Pass by copy") {
|
||||
sts.command_queue.push(&sts, &SharedThreadState::copy_move_test_copy,
|
||||
SharedThreadState::CopyMoveTestType(43));
|
||||
|
||||
sts.message_count_to_read = -1;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
|
||||
CHECK(SharedThreadState::CopyMoveTestType::copy_count == 0);
|
||||
CHECK(SharedThreadState::CopyMoveTestType::move_count == 2);
|
||||
}
|
||||
|
||||
SUBCASE("Pass by reference") {
|
||||
sts.command_queue.push(&sts, &SharedThreadState::copy_move_test_ref,
|
||||
SharedThreadState::CopyMoveTestType(43));
|
||||
|
||||
sts.message_count_to_read = -1;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
|
||||
CHECK(SharedThreadState::CopyMoveTestType::copy_count == 0);
|
||||
CHECK(SharedThreadState::CopyMoveTestType::move_count == 1);
|
||||
}
|
||||
|
||||
SUBCASE("Pass by rvalue reference") {
|
||||
sts.command_queue.push(&sts, &SharedThreadState::copy_move_test_move,
|
||||
SharedThreadState::CopyMoveTestType(43));
|
||||
|
||||
sts.message_count_to_read = -1;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
|
||||
CHECK(SharedThreadState::CopyMoveTestType::copy_count == 0);
|
||||
CHECK(SharedThreadState::CopyMoveTestType::move_count == 1);
|
||||
}
|
||||
}
|
||||
|
||||
sts.destroy_threads();
|
||||
}
|
||||
} // namespace TestCommandQueue
|
||||
|
||||
#endif // TEST_COMMAND_QUEUE_H
|
||||
|
||||
Reference in New Issue
Block a user