netdb: some cleanup
authorMarko Kreen <markokr@gmail.com>
Sun, 27 Mar 2011 20:57:11 +0000 (23:57 +0300)
committerMarko Kreen <markokr@gmail.com>
Mon, 28 Mar 2011 09:01:14 +0000 (12:01 +0300)
- gaia_thread: simplify the lock loop
- gaia_lookup: pass proper sigval to function
- include <string.h>, for memcpy()
- depend on HAVE_PTHREAD not HAVE_PTHREAD_H - to avoid
  messing with non-threaded errno.

configure.ac
usual/netdb.c

index a9aa2e9f668be3b0ffa3d6f0a29ac63d1e376a55..063aa2a22d90ab0372b39776fa0dd23b9ecec26a 100644 (file)
@@ -25,6 +25,8 @@ AC_USUAL_UREGEX
 
 AC_USUAL_LIBEVENT(opt)
 
+AC_USUAL_GETADDRINFO_A
+
 dnl search for common libraries
 AC_SEARCH_LIBS(clock_gettime, rt)
 AC_SEARCH_LIBS(getsockname, socket)
index d7bb4a2fe26da2352e7f9bc933fb1571b4bdd135..707e4deb79640982b0a72a89ff0d68301f6cdf26 100644 (file)
 #include <usual/netdb.h>
 
 #include <usual/socket.h>
+#include <usual/list.h>
 
 /* is compat function needed? */
 #ifndef HAVE_GETADDRINFO_A
 
 /* full compat if threads are available */
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_PTHREAD
 
 #include <pthread.h>
-#include <usual/list.h>
+#include <string.h>
 
 /*
  * Basic blocking lookup
@@ -51,8 +52,7 @@ static void gaia_lookup(pthread_t origin, struct gaicb *list[], int nitems, stru
                pthread_kill(origin, sevp->sigev_signo);
        } else if (sevp->sigev_notify == SIGEV_THREAD) {
                /* call function */
-               union sigval sv;
-               sevp->sigev_notify_function(sv);
+               sevp->sigev_notify_function(sevp->sigev_value);
        }
 }
 
@@ -94,11 +94,12 @@ static void *gaia_lookup_thread(void *arg)
        struct List *el;
 
        gaia_lock_reqs(ctx);
-loop:
        while (1) {
                el = list_pop(&ctx->req_list);
-               if (!el)
-                       break;
+               if (!el) {
+                       pthread_cond_wait(&ctx->cond, &ctx->lock);
+                       continue;
+               }
                gaia_unlock_reqs(ctx);
 
                rq = container_of(el, struct GAIARequest, node);
@@ -107,8 +108,6 @@ loop:
 
                gaia_lock_reqs(ctx);
        }
-       pthread_cond_wait(&ctx->cond, &ctx->lock);
-       goto loop;
 
        return NULL;
 }