diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/go/runtime/lock_js.go | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.zip gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.bz2 |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/go/runtime/lock_js.go')
-rw-r--r-- | libgo/go/runtime/lock_js.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libgo/go/runtime/lock_js.go b/libgo/go/runtime/lock_js.go index f58c915..c038499 100644 --- a/libgo/go/runtime/lock_js.go +++ b/libgo/go/runtime/lock_js.go @@ -11,8 +11,6 @@ import ( ) // js/wasm has no support for threads yet. There is no preemption. -// Waiting for a mutex is implemented by allowing other goroutines -// to run until the mutex gets unlocked. const ( mutex_unlocked = 0 @@ -28,9 +26,16 @@ const ( ) func lock(l *mutex) { - for l.key == mutex_locked { - mcall(gosched_m) + if l.key == mutex_locked { + // js/wasm is single-threaded so we should never + // observe this. + throw("self deadlock") } + gp := getg() + if gp.m.locks < 0 { + throw("lock count") + } + gp.m.locks++ l.key = mutex_locked } @@ -38,6 +43,11 @@ func unlock(l *mutex) { if l.key == mutex_unlocked { throw("unlock of unlocked lock") } + gp := getg() + gp.m.locks-- + if gp.m.locks < 0 { + throw("lock count") + } l.key = mutex_unlocked } |