From bb494dd06b236e0c457e995362ebe9aa5a1ff1ae Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 20 Jul 2022 04:48:45 +0000 Subject: [PATCH] ifdef to remove thread safety FossilOrigin-Name: d4a062d1fbcb84e6e801f6c46ee60536dc79b9ecd92c90f7c706ae95162b7ed0 --- src/fetch.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/fetch.c b/src/fetch.c index f78b15e..95d7112 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -92,43 +92,63 @@ int mastodont_fetch_curl(mastodont_t* mstdnt, curl_easy_setopt(curl, request_t, 1); // Add curl handle to multi, then run and block +#ifndef THREAD_UNSAFE static pthread_mutex_t multi_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif +#ifndef THREAD_UNSAFE pthread_mutex_lock(&multi_mutex); +#endif curl_multi_add_handle(mstdnt->curl, curl); +#ifndef THREAD_UNSAFE pthread_mutex_unlock(&multi_mutex); +#endif int msgs_left; while (running) { +#ifndef THREAD_UNSAFE pthread_mutex_lock(&multi_mutex); +#endif res = curl_multi_perform(mstdnt->curl, &running); +#ifndef THREAD_UNSAFE pthread_mutex_unlock(&multi_mutex); +#endif if (running) res = curl_multi_poll(mstdnt->curl, NULL, 0, 1000, NULL); // Check if our socket is done +#ifndef THREAD_UNSAEF pthread_mutex_lock(&multi_mutex); +#endif while ((msg = curl_multi_info_read(mstdnt->curl, &msgs_left))) { if (msg->msg == CURLMSG_DONE && msg->easy_handle == curl) { status = msg->data.result; +#ifndef THREAD_UNSAFE pthread_mutex_unlock(&multi_mutex); +#endif goto out; } } +#ifndef THREAD_UNSAFE pthread_mutex_unlock(&multi_mutex); +#endif if (res) break; } out: +#ifndef THREAD_UNSAFE pthread_mutex_lock(&multi_mutex); +#endif // Looks like we're done here curl_multi_remove_handle(mstdnt->curl, curl); + #ifndef THREAD_UNSAFE pthread_mutex_unlock(&multi_mutex); +#endif if (list) curl_slist_free_all(list); return status;