From 0c48b9faee2f1f1b74ab28baa5f5526d7fa9430d Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Thu, 14 Dec 2017 00:41:59 +0000 Subject: 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. --- sys/kern/kern_synch.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'sys/kern') 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); + } +} -- cgit v1.2.3