| 21144 | } |
| 21145 | |
| 21146 | void SendInputTask::clearSendInputTaskControllerMap() |
| 21147 | { |
| 21148 | // Lock the global mutex to ensure thread-safe access to the map |
| 21149 | QMutexLocker mapLocker(&s_SendInputTaskControllerMapMutex); |
| 21150 | |
| 21151 | // Iterate through the map to delete each QMutex pointer |
| 21152 | for (SendInputTaskController &controller : s_SendInputTaskControllerMap) |
| 21153 | { |
| 21154 | controller.task_threadpool->clear(); |
| 21155 | // Ensure mutex is unlocked before deleting it |
| 21156 | controller.task_stop_condition->wakeAll(); |
| 21157 | if (controller.task_stop_mutex->try_lock_for(std::chrono::milliseconds(TRY_LOCK_WAIT_TIME))) { |
| 21158 | controller.task_stop_mutex->unlock(); |
| 21159 | } |
| 21160 | else { |
| 21161 | #ifdef DEBUG_LOGOUT_ON |
| 21162 | qDebug().nospace().noquote() << "\033[1;34m[clearSendInputTaskControllerMap] Try lock wait failed, skip this lock!!!\033[0m"; |
| 21163 | continue; |
| 21164 | #endif |
| 21165 | } |
| 21166 | *controller.task_stop_flag = INPUTSTOP_NONE; |
| 21167 | *controller.task_pause_state = KEYSEQUENCE_PAUSE_STATE_NONE; |
| 21168 | |
| 21169 | // Delete the Controller objects |
| 21170 | delete controller.task_stop_mutex; |
| 21171 | delete controller.task_stop_condition; |
| 21172 | delete controller.task_stop_flag; |
| 21173 | delete controller.task_pause_state; |
| 21174 | |
| 21175 | // Delete the ThreadPool |
| 21176 | controller.task_threadpool->waitForDone(100); |
| 21177 | delete controller.task_threadpool; |
| 21178 | } |
| 21179 | |
| 21180 | // Clear the entire map |
| 21181 | s_SendInputTaskControllerMap.clear(); |
| 21182 | |
| 21183 | #ifdef DEBUG_LOGOUT_ON |
| 21184 | qDebug().nospace().noquote() << "\033[1;34m[SendInputTask::clearSendInputTaskControllerMap] Clear all SendInputTask controllers finished.\033[0m"; |
| 21185 | #endif |
| 21186 | } |
| 21187 | |
| 21188 | void SendInputTask::clearSendInputTaskControllerThreadPool() |
| 21189 | { |