]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - resolv/gai_suspend.c
elf: Add DF_1_KMOD, DF_1_WEAKFILTER, DF_1_NOCOMMON to <elf.h>
[thirdparty/glibc.git] / resolv / gai_suspend.c
index b82acb465f0a3f8ecd95980a402d8595e2d5200d..eee3bcebe97691de32b9694cb596110b120d6885 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 <errno.h>
 #include <netdb.h>
@@ -23,7 +22,7 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
-#include "gai_misc.h"
+#include <gai_misc.h>
 
 
 int
@@ -32,9 +31,11 @@ gai_suspend (const struct gaicb *const list[], int ent,
 {
   struct waitlist waitlist[ent];
   struct requestlist *requestlist[ent];
+#ifndef DONT_NEED_GAI_MISC_COND
   pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+#endif
   int cnt;
-  int dummy;
+  unsigned int cntr = 1;
   int none = 1;
   int result;
 
@@ -50,9 +51,11 @@ gai_suspend (const struct gaicb *const list[], int ent,
 
        if (requestlist[cnt] != NULL)
          {
+#ifndef DONT_NEED_GAI_MISC_COND
            waitlist[cnt].cond = &cond;
+#endif
            waitlist[cnt].next = requestlist[cnt]->waiting;
-           waitlist[cnt].counterp = &dummy;
+           waitlist[cnt].counterp = &cntr;
            waitlist[cnt].sigevp = NULL;
            waitlist[cnt].caller_pid = 0;       /* Not needed.  */
            requestlist[cnt]->waiting = &waitlist[cnt];
@@ -78,6 +81,10 @@ gai_suspend (const struct gaicb *const list[], int ent,
         which we must remove.  So defer cancelation for now.  */
       pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
 
+#ifdef DONT_NEED_GAI_MISC_COND
+      result = 0;
+      GAI_MISC_WAIT (result, cntr, timeout, 1);
+#else
       if (timeout == NULL)
        result = pthread_cond_wait (&cond, &__gai_requests_mutex);
       else
@@ -99,6 +106,7 @@ gai_suspend (const struct gaicb *const list[], int ent,
          result = pthread_cond_timedwait (&cond, &__gai_requests_mutex,
                                           &abstime);
        }
+#endif
 
       /* Now remove the entry in the waiting list for all requests
         which didn't terminate.  */
@@ -121,17 +129,19 @@ gai_suspend (const struct gaicb *const list[], int ent,
       /* Now it's time to restore the cancelation state.  */
       pthread_setcancelstate (oldstate, NULL);
 
+#ifndef DONT_NEED_GAI_MISC_COND
       /* Release the conditional variable.  */
       if (pthread_cond_destroy (&cond) != 0)
        /* This must never happen.  */
        abort ();
+#endif
 
       if (result != 0)
        {
          /* An error occurred.  Possibly it's EINTR.  We have to translate
             the timeout error report of `pthread_cond_timedwait' to the
             form expected from `gai_suspend'.  */
-         if (__builtin_expect (result, ETIMEDOUT) == ETIMEDOUT)
+         if (__glibc_likely (result == ETIMEDOUT))
            result = EAI_AGAIN;
          else if (result == EINTR)
            result = EAI_INTR;