]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - resolv/gai_misc.c
hurd: Fix build
[thirdparty/glibc.git] / resolv / gai_misc.c
index b69a8f65785381cc7511ba256da5500a83ac2ee8..69d7086ae67da27736703060d74d4eb2b6650390 100644 (file)
@@ -1,21 +1,20 @@
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/time.h>
 
-#include "gai_misc.h"
+#include <gai_misc.h>
 
 
 
+#ifndef gai_create_helper_thread
+# define gai_create_helper_thread __gai_create_helper_thread
+
+extern inline int
+__gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
+                           void *arg)
+{
+  pthread_attr_t attr;
+
+  /* Make sure the thread is created detached.  */
+  pthread_attr_init (&attr);
+  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+
+  int ret = pthread_create (threadp, &attr, tf, arg);
+
+  (void) pthread_attr_destroy (&attr);
+  return ret;
+}
+#endif
+
+
 /* Pool of request list entries.  */
 static struct requestlist **pool;
 
@@ -132,7 +152,6 @@ get_elem (void)
 
 
 struct requestlist *
-internal_function
 __gai_find_request (const struct gaicb *gaicbp)
 {
   struct requestlist *runp;
@@ -149,7 +168,6 @@ __gai_find_request (const struct gaicb *gaicbp)
 
 
 int
-internal_function
 __gai_remove_request (struct gaicb *gaicbp)
 {
   struct requestlist *runp;
@@ -192,7 +210,6 @@ static void *handle_requests (void *arg);
 /* The main function of the async I/O handling.  It enqueues requests
    and if necessary starts and handles threads.  */
 struct requestlist *
-internal_function
 __gai_enqueue_request (struct gaicb *gaicbp)
 {
   struct requestlist *newp;
@@ -229,16 +246,11 @@ __gai_enqueue_request (struct gaicb *gaicbp)
   if (nthreads < optim.gai_threads && idle_thread_count == 0)
     {
       pthread_t thid;
-      pthread_attr_t attr;
 
       newp->running = 1;
 
-      /* Make sure the thread is created detached.  */
-      pthread_attr_init (&attr);
-      pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
-
       /* Now try to start a thread.  */
-      if (pthread_create (&thid, &attr, handle_requests, newp) == 0)
+      if (gai_create_helper_thread (&thid, handle_requests, newp) == 0)
        /* We managed to enqueue the request.  All errors which can
           happen now can be recognized by calls to `gai_error'.  */
        ++nthreads;
@@ -249,8 +261,11 @@ __gai_enqueue_request (struct gaicb *gaicbp)
              /* We cannot create a thread in the moment and there is
                 also no thread running.  This is a problem.  `errno' is
                 set to EAGAIN if this is only a temporary problem.  */
-             assert (lastp->next == newp);
-             lastp->next = NULL;
+             assert (requests == newp || lastp->next == newp);
+             if (lastp != NULL)
+               lastp->next = NULL;
+             else
+               requests = NULL;
              requests_tail = lastp;
 
              newp->next = freelist;
@@ -281,6 +296,7 @@ __gai_enqueue_request (struct gaicb *gaicbp)
 
 
 static void *
+__attribute__ ((noreturn))
 handle_requests (void *arg)
 {
   struct requestlist *runp = (struct requestlist *) arg;
@@ -348,7 +364,7 @@ handle_requests (void *arg)
          gettimeofday (&now, NULL);
          wakeup_time.tv_sec = now.tv_sec + optim.gai_idle_time;
          wakeup_time.tv_nsec = now.tv_usec * 1000;
-         if (wakeup_time.tv_nsec > 1000000000)
+         if (wakeup_time.tv_nsec >= 1000000000)
            {
              wakeup_time.tv_nsec -= 1000000000;
              ++wakeup_time.tv_sec;
@@ -409,9 +425,7 @@ handle_requests (void *arg)
 
 
 /* Free allocated resources.  */
-static void
-__attribute__ ((unused))
-free_res (void)
+libc_freeres_fn (free_res)
 {
   size_t row;
 
@@ -420,4 +434,3 @@ free_res (void)
 
   free (pool);
 }
-text_set_element (__libc_subfreeres, free_res);