]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - hurd/hurdlock.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / hurd / hurdlock.c
index 0787c196618e76a9a1eb90a81f5caeecefef3a78..995d6a1032bb2860bfa344b349cf3c4d1b2b42da 100644 (file)
@@ -1,5 +1,5 @@
 /* Hurd helpers for lowlevellocks.
-   Copyright (C) 1999-2019 Free Software Foundation, Inc.
+   Copyright (C) 1999-2021 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -47,16 +47,33 @@ int
 __lll_abstimed_wait (void *ptr, int val,
   const struct timespec *tsp, int flags, int clk)
 {
+  if (clk != CLOCK_REALTIME)
+    return EINVAL;
+
   int mlsec = compute_reltime (tsp, clk);
-  return mlsec < 0 ? KERN_TIMEDOUT : lll_timed_wait (ptr, val, mlsec, flags);
+  return mlsec < 0 ? KERN_TIMEDOUT : __lll_timed_wait (ptr, val, mlsec, flags);
+}
+
+int
+__lll_abstimed_wait_intr (void *ptr, int val,
+  const struct timespec *tsp, int flags, int clk)
+{
+  if (clk != CLOCK_REALTIME)
+    return EINVAL;
+
+  int mlsec = compute_reltime (tsp, clk);
+  return mlsec < 0 ? KERN_TIMEDOUT : __lll_timed_wait_intr (ptr, val, mlsec, flags);
 }
 
 int
 __lll_abstimed_xwait (void *ptr, int lo, int hi,
   const struct timespec *tsp, int flags, int clk)
 {
+  if (clk != CLOCK_REALTIME)
+    return EINVAL;
+
   int mlsec = compute_reltime (tsp, clk);
-  return mlsec < 0 ? KERN_TIMEDOUT : lll_timed_xwait (ptr, lo, hi, mlsec,
+  return mlsec < 0 ? KERN_TIMEDOUT : __lll_timed_xwait (ptr, lo, hi, mlsec,
                                                      flags);
 }
 
@@ -64,18 +81,21 @@ int
 __lll_abstimed_lock (void *ptr,
   const struct timespec *tsp, int flags, int clk)
 {
-  if (lll_trylock (ptr) == 0)
+  if (clk != CLOCK_REALTIME)
+    return EINVAL;
+
+  if (__lll_trylock (ptr) == 0)
     return 0;
 
   while (1)
     {
       if (atomic_exchange_acq ((int *)ptr, 2) == 0)
         return 0;
-      else if (tsp->tv_nsec < 0 || tsp->tv_nsec >= 1000000000)
+      else if (! valid_nanoseconds (tsp->tv_nsec))
         return EINVAL;
 
       int mlsec = compute_reltime (tsp, clk);
-      if (mlsec < 0 || lll_timed_wait (ptr, 2, mlsec, flags) == KERN_TIMEDOUT)
+      if (mlsec < 0 || __lll_timed_wait (ptr, 2, mlsec, flags) == KERN_TIMEDOUT)
         return ETIMEDOUT;
     }
 }
@@ -131,7 +151,7 @@ __lll_robust_lock (void *ptr, int flags)
         }
       else
         {
-          lll_timed_wait (iptr, val, wait_time, flags);
+          __lll_timed_wait (iptr, val, wait_time, flags);
           if (wait_time < MAX_WAIT_TIME)
             wait_time <<= 1;
         }
@@ -147,6 +167,9 @@ __lll_robust_abstimed_lock (void *ptr,
   int wait_time = 25;
   unsigned int val;
 
+  if (clk != CLOCK_REALTIME)
+    return EINVAL;
+
   while (1)
     {
       val = *iptr;
@@ -175,7 +198,7 @@ __lll_robust_abstimed_lock (void *ptr,
           else if (mlsec > wait_time)
             mlsec = wait_time;
 
-          int res = lll_timed_wait (iptr, val, mlsec, flags);
+          int res = __lll_timed_wait (iptr, val, mlsec, flags);
           if (res == KERN_TIMEDOUT)
             return ETIMEDOUT;
           else if (wait_time < MAX_WAIT_TIME)
@@ -211,7 +234,7 @@ __lll_robust_unlock (void *ptr, int flags)
     {
       if (val & LLL_WAITERS)
         {
-          lll_set_wake (ptr, 0, flags);
+          __lll_set_wake (ptr, 0, flags);
           break;
         }
       else if (atomic_compare_exchange_weak_release ((unsigned int *)ptr, &val, 0))