diff options
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | request.c | 25 | 
2 files changed, 26 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 7ce3b34..7f4be42 100644 --- a/configure.ac +++ b/configure.ac @@ -4,6 +4,8 @@ AC_PROG_CC  AM_PROG_AR  LT_INIT  PKG_CHECK_MODULES([TIDY], [tidy]) +AC_CHECK_HEADERS([threads.h], +		 [AC_DEFINE([HAVE_THREADS_H])])  AC_CHECK_HEADER_STDBOOL  AC_C_INLINE  AC_CHECK_FUNCS([memset]) @@ -13,7 +13,12 @@ extern emscripten_fetch_attr_t attr;  #else +#ifdef HAVE_THREADS_H  #include <threads.h> +#else +#include <pthread.h> +typedef pthread_t thrd_t; +#endif  #include <curl/curl.h>  extern char *sampleurl; @@ -35,9 +40,17 @@ static size_t append(char *data, size_t size, size_t nmemb, icclient_response *r  	return realsize;  } -static int async(void *arg) +static +#ifdef HAVE_THREADS_H +int +#else +void * +#endif +async(void *arg)  { +#ifdef HAVE_THREADS_H  	int ret = thrd_success; +#endif  	struct container *container = (struct container *)arg;  	CURLcode res = curl_easy_perform(container->response->curl);  	if (container->post) @@ -45,7 +58,9 @@ static int async(void *arg)  	if (res == CURLE_OK && container->handler)  		container->handler(container->response);  	else { +#ifdef HAVE_THREADS_H  		ret = thrd_error; +#endif  #ifdef DEBUG  		const char *error = curl_easy_strerror(res);  #ifdef __ANDROID__ @@ -56,7 +71,11 @@ static int async(void *arg)  #endif  	}  	free(container); +#ifdef HAVE_THREADS_H  	return ret; +#else +	return NULL; +#endif  }  #endif @@ -182,6 +201,10 @@ void request(void (*handler)(icclient_response *), void (*callback)(void *), str  	container->handler = handler;  	container->response = response;  	thrd_t thread; +#ifdef HAVE_THREADS_H  	thrd_create(&thread, async, container); +#else +	pthread_create(&thread, NULL, async, container); +#endif  #endif  }  |