Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/common/include/linux Implement wait_for_com...



details:   https://anonhg.NetBSD.org/src/rev/06d01afd256a
branches:  trunk
changeset: 1027843:06d01afd256a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 00:56:25 2021 +0000

description:
Implement wait_for_completion_timeout.

diffstat:

 sys/external/bsd/common/include/linux/completion.h |  39 +++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)

diffs (53 lines):

diff -r 36b675b9a613 -r 06d01afd256a sys/external/bsd/common/include/linux/completion.h
--- a/sys/external/bsd/common/include/linux/completion.h        Sun Dec 19 00:56:18 2021 +0000
+++ b/sys/external/bsd/common/include/linux/completion.h        Sun Dec 19 00:56:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: completion.h,v 1.7 2020/07/03 16:23:02 maxv Exp $      */
+/*     $NetBSD: completion.h,v 1.8 2021/12/19 00:56:25 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -226,6 +226,43 @@
        }
 }
 
+static inline int
+wait_for_completion_timeout(struct completion *completion, unsigned long ticks)
+{
+       /* XXX Arithmetic overflow...?  */
+       unsigned int start = hardclock_ticks, now;
+       int error;
+
+       mutex_enter(&completion->c_lock);
+
+       /* Wait until c_done is nonzero.  */
+       while (completion->c_done == 0) {
+               error = cv_timedwait(&completion->c_cv, &completion->c_lock,
+                   ticks);
+               if (error)
+                       goto out;
+               now = hardclock_ticks;
+               if (ticks < (now - start)) {
+                       error = EWOULDBLOCK;
+                       goto out;
+               }
+               ticks -= (now - start);
+               start = now;
+       }
+
+       /* Success!  */
+       _completion_claim(completion);
+       error = 0;
+
+out:   mutex_exit(&completion->c_lock);
+       if (error == EWOULDBLOCK) {
+               return 0;
+       } else {
+               KASSERTMSG((error == 0), "error = %d", error);
+               return ticks;
+       }
+}
+
 /*
  * Wait interruptibly for someone to call complete or complete_all.
  */



Home | Main Index | Thread Index | Old Index