| 119 | } |
| 120 | |
| 121 | void GCDDispatchQueue::asyncEnter(const DispatchFunction& function) { |
| 122 | // Check if destroyed before acquiring execution lock |
| 123 | if (wasDestroyed()) { |
| 124 | decrementPendingTaskCount(); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | // Acquire lock to protect function execution |
| 129 | std::lock_guard<std::timed_mutex> lock(_executionMutex); |
| 130 | |
| 131 | // Double-check after acquiring lock (in case teardown happened between checks) |
| 132 | if (wasDestroyed()) { |
| 133 | decrementPendingTaskCount(); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | // Safe to execute - teardown will wait for lock to be released |
| 138 | function(); |
| 139 | |
| 140 | decrementPendingTaskCount(); |
| 141 | } |
| 142 | |
| 143 | bool GCDDispatchQueue::removeTaskId(task_id_t id) { |
| 144 | std::lock_guard<Mutex> guard(_mutex); |