Debian Codegraph @

compiler/natives/src/sync/sync.go

raw
1 // +build js
2
3 package sync
4
5 import "github.com/gopherjs/gopherjs/js"
6
7 var semWaiters = make(map[*uint32][]chan bool)
8
9 func runtime_Semacquire(s *uint32) {
10 if *s == 0 {
11 ch := make(chan bool)
12 semWaiters[s] = append(semWaiters[s], ch)
13 <-ch
14 }
15 *s--
16 }
17
18 // SemacquireMutex is like Semacquire, but for profiling contended Mutexes.
19 // Mutex profiling is not supported, so just use the same implementation as runtime_Semacquire.
20 // TODO: Investigate this. If it's possible to implement, consider doing so, otherwise remove this comment.
21 func runtime_SemacquireMutex(s *uint32, lifo bool) {
22 // TODO: Use lifo if needed/possible.
23 runtime_Semacquire(s)
24 }
25
26 func runtime_Semrelease(s *uint32, handoff bool) {
27 // TODO: Use handoff if needed/possible.
28 *s++
29
30 w := semWaiters[s]
31 if len(w) == 0 {
32 return
33 }
34
35 ch := w[0]
36 w = w[1:]
37 semWaiters[s] = w
38 if len(w) == 0 {
39 delete(semWaiters, s)
40 }
41
42 ch <- true
43 }
44
45 func runtime_notifyListCheck(size uintptr) {}
46
47 func runtime_canSpin(i int) bool {
48 return false
49 }
50
51 // Copy of time.runtimeNano.
52 func runtime_nanotime() int64 {
53 const millisecond = 1000000
54 return js.Global.Get("Date").New().Call("getTime").Int64() * millisecond
55 }