From f6ee4cac39fa83a1691f102760b7f008403acdc2 Mon Sep 17 00:00:00 2001 From: Sipaha Date: Mon, 21 Aug 2017 01:10:44 +0700 Subject: [PATCH] Move wait_for_flush out of queue lock --- core/command_queue_mt.cpp | 2 ++ core/command_queue_mt.h | 63 ++++++++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 823494ff67c..c9edd1d47b2 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -55,6 +55,7 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { while (true) { + lock(); for (int i = 0; i < SYNC_SEMAPHORES; i++) { if (!sync_sems[i].in_use) { @@ -63,6 +64,7 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { break; } } + unlock(); if (idx == -1) { wait_for_flush(); diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index 2e0c4781081..c3e44f731f9 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -911,12 +911,14 @@ public: template void push_and_ret(T *p_instance, M p_method, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet0 *cmd = allocate_and_lock >(); cmd->instance = p_instance; cmd->method = p_method; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -928,13 +930,15 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet1 *cmd = allocate_and_lock >(); cmd->instance = p_instance; cmd->method = p_method; cmd->p1 = p1; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -946,6 +950,8 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet2 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -953,7 +959,7 @@ public: cmd->p1 = p1; cmd->p2 = p2; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -965,6 +971,8 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet3 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -973,7 +981,7 @@ public: cmd->p2 = p2; cmd->p3 = p3; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -985,6 +993,8 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet4 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -994,7 +1004,7 @@ public: cmd->p3 = p3; cmd->p4 = p4; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1006,6 +1016,8 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet5 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1016,7 +1028,7 @@ public: cmd->p4 = p4; cmd->p5 = p5; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1028,6 +1040,8 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet6 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1039,7 +1053,7 @@ public: cmd->p5 = p5; cmd->p6 = p6; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1051,6 +1065,8 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet7 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1063,7 +1079,7 @@ public: cmd->p6 = p6; cmd->p7 = p7; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1075,6 +1091,8 @@ public: template void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet8 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1088,7 +1106,7 @@ public: cmd->p7 = p7; cmd->p8 = p8; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1100,12 +1118,13 @@ public: template void push_and_sync(T *p_instance, M p_method) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync0 *cmd = allocate_and_lock >(); cmd->instance = p_instance; cmd->method = p_method; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1117,13 +1136,14 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync1 *cmd = allocate_and_lock >(); cmd->instance = p_instance; cmd->method = p_method; cmd->p1 = p1; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1135,6 +1155,8 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync2 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1142,7 +1164,6 @@ public: cmd->p1 = p1; cmd->p2 = p2; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1154,6 +1175,8 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync3 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1162,7 +1185,6 @@ public: cmd->p2 = p2; cmd->p3 = p3; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1174,6 +1196,8 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync4 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1183,7 +1207,6 @@ public: cmd->p3 = p3; cmd->p4 = p4; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1195,6 +1218,8 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync5 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1205,7 +1230,6 @@ public: cmd->p4 = p4; cmd->p5 = p5; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1217,6 +1241,8 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync6 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1228,7 +1254,6 @@ public: cmd->p5 = p5; cmd->p6 = p6; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1240,6 +1265,8 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync7 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1252,7 +1279,6 @@ public: cmd->p6 = p6; cmd->p7 = p7; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1264,6 +1290,8 @@ public: template void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync8 *cmd = allocate_and_lock >(); cmd->instance = p_instance; @@ -1277,7 +1305,6 @@ public: cmd->p7 = p7; cmd->p8 = p8; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock();