@@ -105,6 +105,7 @@ class CommandQueueMT {
105105
106106 static const uint32_t DEFAULT_COMMAND_MEM_SIZE_KB = 64 ;
107107
108+ bool unique_flusher = false ;
108109 BinaryMutex mutex;
109110 LocalVector<uint8_t > command_mem;
110111 ConditionVariable sync_cond_var;
@@ -154,29 +155,38 @@ class CommandQueueMT {
154155 }
155156
156157 void _flush () {
158+ MutexLock lock (mutex);
159+
157160 if (unlikely (flush_read_ptr)) {
158161 // Re-entrant call.
159162 return ;
160163 }
161164
162- MutexLock lock (mutex);
163-
164165 while (flush_read_ptr < command_mem.size ()) {
165166 uint64_t size = *(uint64_t *)&command_mem[flush_read_ptr];
166167 flush_read_ptr += 8 ;
167168 CommandBase *cmd = reinterpret_cast <CommandBase *>(&command_mem[flush_read_ptr]);
168- uint32_t allowance_id = WorkerThreadPool::thread_enter_unlock_allowance_zone (lock);
169- cmd->call ();
170- WorkerThreadPool::thread_exit_unlock_allowance_zone (allowance_id);
169+
170+ if (unique_flusher) {
171+ // A single thread will pump; the lock is only needed for the command queue itself.
172+ lock.temp_unlock ();
173+ cmd->call ();
174+ lock.temp_relock ();
175+ } else {
176+ // At least we can unlock during WTP operations.
177+ uint32_t allowance_id = WorkerThreadPool::thread_enter_unlock_allowance_zone (lock);
178+ cmd->call ();
179+ WorkerThreadPool::thread_exit_unlock_allowance_zone (allowance_id);
180+ }
171181
172182 // Handle potential realloc due to the command and unlock allowance.
173183 cmd = reinterpret_cast <CommandBase *>(&command_mem[flush_read_ptr]);
174184
175185 if (unlikely (cmd->sync )) {
176186 sync_head++;
177- lock.~MutexLock (); // Give an opportunity to awaiters right away.
187+ lock.temp_unlock (); // Give an opportunity to awaiters right away.
178188 sync_cond_var.notify_all ();
179- new (& lock) MutexLock (mutex );
189+ lock. temp_relock ( );
180190 // Handle potential realloc happened during unlock.
181191 cmd = reinterpret_cast <CommandBase *>(&command_mem[flush_read_ptr]);
182192 }
@@ -252,6 +262,6 @@ class CommandQueueMT {
252262 pump_task_id = p_task_id;
253263 }
254264
255- CommandQueueMT ();
265+ CommandQueueMT (bool p_unique_flusher = false );
256266 ~CommandQueueMT ();
257267};
0 commit comments