Refactor CommandQueueMT
* RingBuffer had no reason to be in this context * A single buffer is used that can grow as much as the game needs. This should make thread loading entirely reliable.
This commit is contained in:
parent
0818a466c0
commit
c66b2651a6
7 changed files with 39 additions and 211 deletions
|
|
@ -156,7 +156,7 @@ public:
|
|||
command_queue.flush_all();
|
||||
}
|
||||
for (int i = 0; i < message_count_to_read; i++) {
|
||||
command_queue.wait_and_flush_one();
|
||||
command_queue.wait_and_flush();
|
||||
}
|
||||
message_count_to_read = 0;
|
||||
|
||||
|
|
@ -276,50 +276,6 @@ TEST_CASE("[CommandQueue] Test Queue Basics") {
|
|||
ProjectSettings::get_singleton()->property_get_revert(COMMAND_QUEUE_SETTING));
|
||||
}
|
||||
|
||||
TEST_CASE("[CommandQueue] Test Waiting at Queue Full") {
|
||||
const char *COMMAND_QUEUE_SETTING = "memory/limits/command_queue/multithreading_queue_size_kb";
|
||||
ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING, 1);
|
||||
SharedThreadState sts;
|
||||
sts.init_threads();
|
||||
|
||||
int msgs_to_add = 24; // a queue of size 1kB fundamentally cannot fit 24 matrices.
|
||||
for (int i = 0; i < msgs_to_add; i++) {
|
||||
sts.add_msg_to_write(SharedThreadState::TEST_MSG_FUNC1_TRANSFORM);
|
||||
}
|
||||
sts.writer_threadwork.main_start_work();
|
||||
// If we call main_wait_for_done, we will deadlock. So instead...
|
||||
sts.message_count_to_read = 1;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
CHECK_MESSAGE(sts.func1_count == 1,
|
||||
"Reader should have read one message");
|
||||
CHECK_MESSAGE(sts.during_writing,
|
||||
"Writer thread should still be blocked on writing.");
|
||||
sts.message_count_to_read = msgs_to_add - 3;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
CHECK_MESSAGE(sts.func1_count >= msgs_to_add - 3,
|
||||
"Reader should have read most messages");
|
||||
sts.writer_threadwork.main_wait_for_done();
|
||||
CHECK_MESSAGE(sts.during_writing == false,
|
||||
"Writer thread should no longer be blocked on writing.");
|
||||
sts.message_count_to_read = 2;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
sts.message_count_to_read = -1;
|
||||
sts.reader_threadwork.main_start_work();
|
||||
sts.reader_threadwork.main_wait_for_done();
|
||||
CHECK_MESSAGE(sts.func1_count == msgs_to_add,
|
||||
"Reader should have read all messages");
|
||||
|
||||
sts.destroy_threads();
|
||||
|
||||
CHECK_MESSAGE(sts.func1_count == msgs_to_add,
|
||||
"Reader should have read no additional messages after join");
|
||||
ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING,
|
||||
ProjectSettings::get_singleton()->property_get_revert(COMMAND_QUEUE_SETTING));
|
||||
}
|
||||
|
||||
TEST_CASE("[CommandQueue] Test Queue Wrapping to same spot.") {
|
||||
const char *COMMAND_QUEUE_SETTING = "memory/limits/command_queue/multithreading_queue_size_kb";
|
||||
ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue