shithub: mc

Download patch

ref: 36b4210be2a5d51607ba614d08e8369b19ca1e65
parent: abadb828b42e44dd0e50be143745a0c15d8c6c83
author: Ori Bernstein <ori@eigenstate.org>
date: Thu May 5 17:41:38 EDT 2016

Pull sleep into system specific code.

--- a/lib/std/slput.myr
+++ b/lib/std/slput.myr
@@ -24,5 +24,6 @@
 	for var i = idx; i < sl#.len - 1; i++
 		sl#[i] = sl#[i + 1]
 	;;
-	-> sl#[:sl#.len - 1]
+	sl# = sl#[:sl#.len - 1]
+	-> sl#
 }
--- a/lib/std/syswrap+plan9.myr
+++ b/lib/std/syswrap+plan9.myr
@@ -66,6 +66,7 @@
 	const fork	: (-> pid)
 	const execv	: (cmd : byte[:], args : byte[:][:] -> errno)
 	const execve	: (cmd : byte[:], args : byte[:][:], env : byte[:][:] -> errno)
+	const nanosleep	: (nsecs : uint64 -> errno)
 
 	pkglocal const Canunmap	: bool = true
 	pkglocal const getmem	: (sz : size -> byte#)
@@ -198,9 +199,16 @@
 	sys.exec(cmd, args)
 	-> lasterr()
 }
+
 const execve	= {cmd, args, env;
 	sys.exec(cmd, args)
 	-> lasterr()
+}
+
+const nanosleep = {nsecs
+	if sys.sleep(nsecs/1_000_000) < 0
+		-> lasterr()
+	;;
 }
 
 /* memory stuff */
--- a/lib/std/syswrap+posixy.myr
+++ b/lib/std/syswrap+posixy.myr
@@ -103,7 +103,6 @@
 const fork	= {;		-> sys.fork() castto(pid)}
 const execv	= {cmd, args;	-> sys.execv(cmd, args) castto(errno)}
 const execve	= {cmd, args, env;	-> sys.execve(cmd, args, env) castto(errno)}
-const sleep	= {time;	sys.sleep(time)}
 
 /* memory stuff */
 const getmem	= {sz;		-> sys.mmap(0 castto(byte#), sz castto(sys.size), sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)}
--- a/lib/std/syswrap-ss+freebsd.myr
+++ b/lib/std/syswrap-ss+freebsd.myr
@@ -5,12 +5,28 @@
 use "die"
 
 pkg std =
+	const nanosleep	: (nsecs : uint64 -> errno)
 	$noret const exit	: (status:int -> void)
+
 	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
 ;;
 
-const exit	= {status;	sys.exit(status)}
-const bgetcwd	= {buf
+const nanosleep	= {nsecs
+	var req, rem
+	var s, ns
+
+	s = nsecs / 1_000_000_000
+	ns = nsecs % 1_000_000_000
+	req = [.sec = s, .nsec = ns]
+
+	-> sys.nanosleep(&req, &rem) castto(errno)
+}
+
+const exit = {status
+	sys.exit(status)
+}
+
+const bgetcwd = {buf
 	var res
 
 	res = sys.__getcwd(buf) castto(errno)
--- a/lib/std/syswrap-ss+linux.myr
+++ b/lib/std/syswrap-ss+linux.myr
@@ -2,12 +2,28 @@
 use "errno"
 
 pkg std =
+	const nanosleep	: (nsecs : uint64 -> errno)
 	$noret const exit	: (status:int -> void)
+
 	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
 ;;
 
-const exit	= {status;	sys.exit_group(status)}
-const bgetcwd	= {buf;
+const nanosleep	= {nsecs
+	var req, rem
+	var s, ns
+
+	s = nsecs / 1_000_000_000
+	ns = nsecs % 1_000_000_000
+	req = [.sec = s, .nsec = ns]
+
+	-> sys.nanosleep(&req, &rem) castto(errno)
+}
+
+const exit = {status;
+	sys.exit_group(status)
+}
+
+const bgetcwd = {buf;
 	var err
 	err = sys.getcwd(buf) castto(errno)
 	/*
--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -862,7 +862,6 @@
 	const clock_getres	: (clk : clock, ts : timespec# -> int32)
 	const clock_gettime	: (clk : clock, ts : timespec# -> int32)
 	const clock_settime	: (clk : clock, ts : timespec# -> int32)
-	const sleep	: (time : uint64 -> int32)
 	const nanosleep	: (req : timespec#, rem : timespec# -> int32)
 
 	/* system information */
@@ -991,13 +990,6 @@
 const clock_getres = {clk, ts;	-> syscall(Sysclock_getres, clockid(clk), a(ts)) castto(int32)}
 const clock_gettime = {clk, ts;	-> syscall(Sysclock_gettime, clockid(clk), a(ts)) castto(int32)}
 const clock_settime = {clk, ts;	-> syscall(Sysclock_settime, clockid(clk), a(ts)) castto(int32)}
-
-const sleep = {time
-	var req, rem
-	req = [.sec = time, .nsec = 0]
-	-> nanosleep(&req, &rem)
-}
-
 const nanosleep	= {req, rem;	-> syscall(Sysnanosleep, a(req), a(rem)) castto(int32)}
 
 
--- a/lib/sys/sys+linux-x64.myr
+++ b/lib/sys/sys+linux-x64.myr
@@ -711,7 +711,6 @@
 	const clock_getres	: (clk : clock, ts : timespec# -> int32)
 	const clock_gettime	: (clk : clock, ts : timespec# -> int32)
 	const clock_settime	: (clk : clock, ts : timespec# -> int32)
-	const sleep	: (time : uint64 -> int32)
 	const nanosleep	: (req : timespec#, rem : timespec# -> int32)
 
 	/* system information */
@@ -841,13 +840,6 @@
 const clock_getres = {clk, ts;	-> syscall(Sysclock_getres, clockid(clk), a(ts)) castto(int32)}
 const clock_gettime = {clk, ts;	-> syscall(Sysclock_gettime, clockid(clk), a(ts)) castto(int32)}
 const clock_settime = {clk, ts;	-> syscall(Sysclock_settime, clockid(clk), a(ts)) castto(int32)}
-
-const sleep = {time
-	var req, rem
-	req = [.sec = time, .nsec = 0]
-	-> nanosleep(&req, &rem)
-}
-
 const nanosleep	= {req, rem;	-> syscall(Sysnanosleep, a(req), a(rem)) castto(int32)}
 
 /* system information */