blob: 5690f9fe839f275bc8e627b2e19f3cb301543f8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// +build js
package poll
import "time"
// pollDesc is a no-op implementation of an I/O poller for GOARCH=js.
//
// Its implementation is based on NaCL in gc compiler (see GOROOT/src/internal/poll/fd_poll_nacl.go),
// but it does even less.
type pollDesc struct {
closing bool
}
func (pd *pollDesc) init(fd *FD) error { return nil }
func (pd *pollDesc) close() {}
func (pd *pollDesc) evict() { pd.closing = true }
func (pd *pollDesc) prepare(mode int, isFile bool) error {
if pd.closing {
return errClosing(isFile)
}
return nil
}
func (pd *pollDesc) prepareRead(isFile bool) error { return pd.prepare('r', isFile) }
func (pd *pollDesc) prepareWrite(isFile bool) error { return pd.prepare('w', isFile) }
func (pd *pollDesc) wait(mode int, isFile bool) error {
if pd.closing {
return errClosing(isFile)
}
return ErrTimeout
}
func (pd *pollDesc) waitRead(isFile bool) error { return pd.wait('r', isFile) }
func (pd *pollDesc) waitWrite(isFile bool) error { return pd.wait('w', isFile) }
func (*pollDesc) waitCanceled(mode int) {}
func (*pollDesc) pollable() bool { return true }
func (*FD) SetDeadline(t time.Time) error { return nil }
func (*FD) SetReadDeadline(t time.Time) error { return nil }
func (*FD) SetWriteDeadline(t time.Time) error { return nil }
// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr {
return ^uintptr(0)
}
// Copy of sync.runtime_Semacquire.
func runtime_Semacquire(s *uint32) {
if *s == 0 {
ch := make(chan bool)
semWaiters[s] = append(semWaiters[s], ch)
<-ch
}
*s--
}
// Copy of sync.runtime_Semrelease.
func runtime_Semrelease(s *uint32) {
*s++
w := semWaiters[s]
if len(w) == 0 {
return
}
ch := w[0]
w = w[1:]
semWaiters[s] = w
if len(w) == 0 {
delete(semWaiters, s)
}
ch <- true
}
var semWaiters = make(map[*uint32][]chan bool)
|