From 1336fe3b76c6f7db8c1427b1d395ad0d07d97cda Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Tue, 29 Oct 2013 21:25:04 +0100 Subject: [PATCH] Get rid of pthread usage in getdns_general_sync --- configure.ac | 3 +-- src/sync.c | 75 +++++++--------------------------------------------- 2 files changed, 11 insertions(+), 67 deletions(-) diff --git a/configure.ac b/configure.ac index 938fd88e..822ba2be 100644 --- a/configure.ac +++ b/configure.ac @@ -26,10 +26,9 @@ AC_PROG_CPP # Checks for libraries. found_all_libs=1 -AC_MSG_NOTICE([Checking for dependencies libevent, ldns, pthread, and unbound]) +AC_MSG_NOTICE([Checking for dependencies libevent, ldns and unbound]) AC_CHECK_LIB([event_core], [event_base_new], [], [found_all_libs=0]) AC_CHECK_LIB([ldns], [ldns_dname_new_frm_str], [], [found_all_libs=0]) -AC_CHECK_LIB([pthread], [pthread_create], [], [found_all_libs=0]) AC_CHECK_LIB([unbound], [ub_ctx_set_event], [], [found_all_libs=0]) if test $found_all_libs == 0 then diff --git a/src/sync.c b/src/sync.c index bdd2b62b..e7f6537d 100644 --- a/src/sync.c +++ b/src/sync.c @@ -28,7 +28,6 @@ */ #include -#include #include #include #include "context.h" @@ -38,43 +37,15 @@ /* stuff to make it compile pedantically */ #define UNUSED_PARAM(x) ((void)(x)) -/* struct used for the request */ -typedef struct sync_request_data { - getdns_context_t context; - char* name; - uint16_t request_type; - getdns_dict *extensions; - getdns_return_t response_status; - getdns_dict **response; -} sync_request_data; - static void sync_callback_func(getdns_context_t context, uint16_t callback_type, struct getdns_dict *response, void *userarg, getdns_transaction_t transaction_id) { - sync_request_data* req_data = userarg; - *(req_data->response) = response; + + *((getdns_dict **)userarg) = response; } -static void * request_thread_start(void *arg) { - struct sync_request_data *req_data = arg; - - req_data->response_status = getdns_general_ub(req_data->context->unbound_sync, - req_data->context->event_base_sync, - req_data->context, - req_data->name, - req_data->request_type, - req_data->extensions, - req_data, - NULL, - sync_callback_func); - - event_base_dispatch(req_data->context->event_base_sync); - return NULL; -} - - getdns_return_t getdns_general_sync( getdns_context_t context, @@ -85,41 +56,15 @@ getdns_general_sync( struct getdns_dict **response ) { - /* we will cheat and spawn a thread */ - /* set up for sync resolution */ - pthread_t thread; - pthread_attr_t attr; - sync_request_data req_data = { - context, - strdup(name), - request_type, - extensions, - GETDNS_RETURN_GOOD, - response - }; + getdns_return_t response_status; - /* create the thread */ - int ret = pthread_attr_init(&attr); - if (ret != 0) { - free(req_data.name); - return GETDNS_RETURN_GENERIC_ERROR; - } - ret = pthread_create(&thread, &attr, request_thread_start, &req_data); - if (ret != 0) { - pthread_attr_destroy(&attr); - free(req_data.name); - return GETDNS_RETURN_GENERIC_ERROR; - } - /* wait for the thread */ - ret = pthread_join(thread, NULL); - /* delete attr */ - pthread_attr_destroy(&attr); - if (ret != 0) { - free(req_data.name); - return GETDNS_RETURN_GENERIC_ERROR; - } - free(req_data.name); - return req_data.response_status; + response_status = getdns_general_ub(context->unbound_sync, context->event_base_sync, + context, name, request_type, extensions, + (void *)response, NULL, sync_callback_func); + + event_base_dispatch(context->event_base_sync); + + return response_status; } getdns_return_t