| 133 | |
| 134 | |
| 135 | void cChunkSender::Execute(void) |
| 136 | { |
| 137 | while (!m_ShouldTerminate) |
| 138 | { |
| 139 | cCSLock Lock(m_CS); |
| 140 | while (m_ChunksReady.empty() && m_SendChunks.empty()) |
| 141 | { |
| 142 | int RemoveCount = m_RemoveCount; |
| 143 | m_RemoveCount = 0; |
| 144 | cCSUnlock Unlock(Lock); |
| 145 | for (int i = 0; i < RemoveCount; i++) |
| 146 | { |
| 147 | m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted |
| 148 | } |
| 149 | m_evtQueue.Wait(); |
| 150 | if (m_ShouldTerminate) |
| 151 | { |
| 152 | return; |
| 153 | } |
| 154 | } // while (empty) |
| 155 | |
| 156 | if (!m_ChunksReady.empty()) |
| 157 | { |
| 158 | // Take one from the queue: |
| 159 | cChunkCoords Coords(m_ChunksReady.front()); |
| 160 | m_ChunksReady.pop_front(); |
| 161 | Lock.Unlock(); |
| 162 | |
| 163 | SendChunk(Coords.m_ChunkX, Coords.m_ChunkY, Coords.m_ChunkZ, NULL); |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | // Take one from the queue: |
| 168 | sSendChunk Chunk(m_SendChunks.front()); |
| 169 | m_SendChunks.pop_front(); |
| 170 | Lock.Unlock(); |
| 171 | |
| 172 | SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkY, Chunk.m_ChunkZ, Chunk.m_Client); |
| 173 | } |
| 174 | Lock.Lock(); |
| 175 | int RemoveCount = m_RemoveCount; |
| 176 | m_RemoveCount = 0; |
| 177 | Lock.Unlock(); |
| 178 | for (int i = 0; i < RemoveCount; i++) |
| 179 | { |
| 180 | m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted |
| 181 | } |
| 182 | } // while (!mShouldTerminate) |
| 183 | } |
| 184 | |
| 185 | |
| 186 | |