From: Holger Schemel Date: Wed, 23 Jun 2021 07:50:45 +0000 (+0200) Subject: changed thread functions to be more generic regarding passed data X-Git-Tag: 4.3.0.0~121 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=a88bb81d863f922e518970df22fcff1bb3c15c4c;p=rocksndiamonds.git changed thread functions to be more generic regarding passed data --- diff --git a/src/files.c b/src/files.c index 93d38e7c..2daffc83 100644 --- a/src/files.c +++ b/src/files.c @@ -9002,14 +9002,10 @@ void SaveScore(int nr) SaveScoreToFilename(filename); } -static void ExecuteAsThread(SDL_ThreadFunction function, char *name, int data, +static void ExecuteAsThread(SDL_ThreadFunction function, char *name, void *data, char *error) { - static int data_static; - - data_static = data; - - SDL_Thread *thread = SDL_CreateThread(function, name, &data_static); + SDL_Thread *thread = SDL_CreateThread(function, name, data); if (thread != NULL) SDL_DetachThread(thread); @@ -9098,17 +9094,28 @@ static void DownloadServerScoreToCache(int nr) checked_free(response); } -static int DownloadServerScoreToCacheThread(void *data) +struct DownloadServerScoreToCacheThreadData { - DownloadServerScoreToCache(*(int *)data); + int level_nr; +}; + +static int DownloadServerScoreToCacheThread(void *data_raw) +{ + struct DownloadServerScoreToCacheThreadData *data = data_raw; + + DownloadServerScoreToCache(data->level_nr); return 0; } static void DownloadServerScoreToCacheAsThread(int nr) { + static struct DownloadServerScoreToCacheThreadData data; + + data.level_nr = nr; + ExecuteAsThread(DownloadServerScoreToCacheThread, - "DownloadServerScoreToCache", nr, + "DownloadServerScoreToCache", &data, "download scores from server"); } @@ -9353,17 +9360,28 @@ static void UploadScoreToServer(int nr) checked_free(response); } -static int UploadScoreToServerThread(void *data) +struct UploadScoreToServerThreadData +{ + int level_nr; +}; + +static int UploadScoreToServerThread(void *data_raw) { - UploadScoreToServer(*(int *)data); + struct UploadScoreToServerThreadData *data = data_raw; + + UploadScoreToServer(data->level_nr); return 0; } static void UploadScoreToServerAsThread(int nr) { + static struct UploadScoreToServerThreadData data; + + data.level_nr = nr; + ExecuteAsThread(UploadScoreToServerThread, - "UploadScoreToServer", nr, + "UploadScoreToServer", &data, "upload score to server"); }