go/src
Matthew Dempsky d955dfb007 runtime: cleanup openbsd semasleep implementation
The previous implementation had several subtle issues.  It's not
clear if any of these could actually be causing the flakiness
problems on openbsd/386, but fixing them should only help.

1. thrsleep() is implemented internally as unlock, then test *abort
(if abort != nil), then tsleep().  Under the current code, that makes
it theoretically possible that semasleep()/thrsleep() could release
waitsemalock, then a racing semawakeup() could acquire the lock,
increment waitsemacount, and call thrwakeup()/wakeup() before
thrsleep() reaches tsleep().  (In practice, OpenBSD's big kernel lock
seems unlikely to let this actually happen.)

The proper way to avoid this is to pass &waitsemacount as the abort
pointer to thrsleep so thrsleep knows to re-check it before going to
sleep, and to wakeup if it's non-zero.  Then we avoid any races.
(I actually suspect openbsd's sema{sleep,wakeup}() could be further
simplified using cas/xadd instead of locks, but I don't want to be
more intrusive than necessary so late in the 1.4 release cycle.)

2. semasleep() takes a relative sleep duration, but thrsleep() needs
an absolute sleep deadline.  Instead of recomputing the deadline each
iteration, compute it once up front and use (*Timespec)(nil) to signify
no deadline.  Ensures we retry properly if there's a spurious wakeup.

3. Instead of assuming if thrsleep() woke up and waitsemacount wasn't
available that we must have hit the deadline, check that the system
call returned EWOULDBLOCK.

4. Instead of assuming that 64-bit systems are little-endian, compute
timediv() using a temporary int32 nsec and then assign it to tv_nsec.

LGTM=iant
R=jsing, iant
CC=golang-codereviews
https://golang.org/cl/137960043
2014-09-09 17:41:48 -07:00
..
archive build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
bufio build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
builtin build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
bytes build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
cmd runtime: assume precisestack, copystack, StackCopyAlways, ScanStackByFrames 2014-09-09 13:39:57 -04:00
compress build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
container build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
crypto build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
database/sql build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
debug build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
encoding build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
errors build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
expvar build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
flag build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
fmt fmt: fix allocation test 2014-09-09 11:45:46 -07:00
go go/parser: fix (pathological) corner case 2014-09-08 14:54:00 -07:00
hash build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
html build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
image build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
index/suffixarray build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
internal/syscall build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
io build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
lib9
libbio
liblink runtime: assume precisestack, copystack, StackCopyAlways, ScanStackByFrames 2014-09-09 13:39:57 -04:00
log build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
math build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
mime build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
net net: don't set wrong option for controlling tcp keepalive on openbsd 2014-09-09 07:22:11 +09:00
os build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
path build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
reflect build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
regexp build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
runtime runtime: cleanup openbsd semasleep implementation 2014-09-09 17:41:48 -07:00
sort build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
strconv strconv: fix documentation for CanBackquote. 2014-09-09 11:45:36 -07:00
strings build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
sync build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
syscall syscall: keep Windows syscall pointers live too 2014-09-08 17:47:12 -07:00
testing testing: read coverage counters atomically 2014-09-09 12:31:07 -07:00
text build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
time build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
unicode build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
unsafe build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
Make.dist
all.bash
all.bat
all.rc
androidtest.bash androidtest.bash: adjustment for move from src/pkg to src 2014-09-08 10:07:26 -04:00
clean.bash
clean.bat
clean.rc
make.bash build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
make.bat build: fix windows make.bat 2014-09-07 07:31:53 -04:00
make.rc build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
nacltest.bash build: more adjustments for move from src/pkg to src 2014-09-08 00:22:40 -04:00
race.bash
race.bat
run.bash run.bash: run misc/cgo/testgodefs/test.bash 2014-08-12 07:13:52 -07:00
run.bat
run.rc
sudo.bash