summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-07-18 00:24:29 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-18 00:24:29 -0700
commitaa40abd25de6fc94621a41b360b5808b3aa57b55 (patch)
treef7659260c4991a982887f29efe66e22d5f97620e
parent492aca3ff6f829ee09c52e17c86a808430ee7df4 (diff)
downloadmc-aa40abd25de6fc94621a41b360b5808b3aa57b55.tar.gz
Add the abiity to wait for any proc.
-rw-r--r--lib/std/wait+posixy.myr32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/std/wait+posixy.myr b/lib/std/wait+posixy.myr
index bd9ae31..b04aab4 100644
--- a/lib/std/wait+posixy.myr
+++ b/lib/std/wait+posixy.myr
@@ -12,13 +12,27 @@ pkg std =
;;
const wait : (pid : pid -> waitstatus)
+ const waitany : (-> (pid, waitstatus))
;;
+const waitany = {
+ match dowait(-1)
+ | (p, st): -> ((p : pid), st)
+ ;;
+}
+
const wait = {pid
- var st
+ match dowait(pid)
+ | (_, st): -> st
+ ;;
+}
+
+const dowait = {pid
+ var st, p
:again
- if sys.waitpid((pid : sys.pid), &st, 0) > 0
+ p = sys.waitpid((pid : sys.pid), &st, 0)
+ if p > 0
match sys.waitstatus(st)
/*
when a process stops, eg, if paused by a debugger,
@@ -26,16 +40,12 @@ const wait = {pid
a process exits. Loop instead.
*/
| `sys.Waitstop sig: goto again
- | `sys.Waitfail fail: -> `Waiterror
- | `sys.Waitsig sig: -> `Wsignalled
- | `sys.Waitexit status:
- if status == 0
- -> `Wsuccess
- else
- -> `Wfailure
- ;;
+ | `sys.Waitfail fail: -> (p, `Waiterror)
+ | `sys.Waitsig sig: -> (p, `Wsignalled)
+ | `sys.Waitexit 0: -> (p, `Wsuccess)
+ | `sys.Waitexit _: -> (p, `Wfailure)
;;
;;
- -> `Waiterror
+ -> (-1, `Waiterror)
}