C client: Fix crash on process exit on linux

This commit is contained in:
UnknownShadow200 2018-09-11 09:24:53 +10:00
parent cd1961f588
commit a88d912859

View File

@ -235,20 +235,21 @@ static void AsyncDownloader_CompleteResult(struct AsyncRequest* request) {
} }
static void AsyncDownloader_WorkerFunc(void) { static void AsyncDownloader_WorkerFunc(void) {
while (true) { for (;;) {
struct AsyncRequest request; struct AsyncRequest request;
bool hasRequest = false; bool hasRequest = false, stop;
Mutex_Lock(async_pendingMutex); Mutex_Lock(async_pendingMutex);
{ {
if (async_terminate) return; stop = async_terminate;
if (async_pending.Count) { if (!stop && async_pending.Count) {
request = async_pending.Requests[0]; request = async_pending.Requests[0];
hasRequest = true; hasRequest = true;
AsyncRequestList_RemoveAt(&async_pending, 0); AsyncRequestList_RemoveAt(&async_pending, 0);
} }
} }
Mutex_Unlock(async_pendingMutex); Mutex_Unlock(async_pendingMutex);
if (stop) return;
if (hasRequest) { if (hasRequest) {
Platform_LogConst("Got something to do!"); Platform_LogConst("Got something to do!");
@ -283,8 +284,8 @@ static void AsyncDownloader_Init(void) {
Http_Init(); Http_Init();
async_waitable = Waitable_Create(); async_waitable = Waitable_Create();
async_pendingMutex = Mutex_Create(); async_pendingMutex = Mutex_Create();
async_processedMutex = Mutex_Create(); async_processedMutex = Mutex_Create();
async_curRequestMutex = Mutex_Create(); async_curRequestMutex = Mutex_Create();
async_workerThread = Thread_Start(AsyncDownloader_WorkerFunc, false); async_workerThread = Thread_Start(AsyncDownloader_WorkerFunc, false);
} }