diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2017-12-14 00:41:59 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2017-12-14 00:41:59 +0000 |
commit | 0c48b9faee2f1f1b74ab28baa5f5526d7fa9430d (patch) | |
tree | f672094584e78ad18de433f760d56ae9ad50db48 /sys/kern | |
parent | f57cf99093f2f8619ea7a30efd68c3ac4a32ad10 (diff) |
add code to provide simple wait condition handling.
this will be used to replace the bare sleep_state handling in a
bunch of places, starting with the barriers.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_synch.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 7fb23449560..ea28288d375 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.142 2017/12/04 09:38:20 mpi Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.143 2017/12/14 00:41:58 dlg Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -704,3 +704,31 @@ refcnt_finalize(struct refcnt *r, const char *wmesg) sleep_finish(&sls, refcnt); } } + +void +cond_init(struct cond *c) +{ + c->c_wait = 1; +} + +void +cond_signal(struct cond *c) +{ + c->c_wait = 0; + + wakeup_one(c); +} + +void +cond_wait(struct cond *c, const char *wmesg) +{ + struct sleep_state sls; + int wait; + + wait = c->c_wait; + while (wait) { + sleep_setup(&sls, c, PWAIT, wmesg); + wait = c->c_wait; + sleep_finish(&sls, wait); + } +} |