GoPLS Viewer

Home|gopls/go/ssa/interp/testdata/src/sync/sync.go
1package sync
2
3// Rudimentary implementation of a mutex for interp tests.
4type Mutex struct {
5    c chan int // Mutex is held when held c!=nil and is empty. Access is guarded by g.
6}
7
8func (m *MutexLock() {
9    c := ch(m)
10    <-c
11}
12
13func (m *MutexUnlock() {
14    c := ch(m)
15    c <- 1
16}
17
18// sequentializes Mutex.c access.
19var g = make(chan int1)
20
21func init() {
22    g <- 1
23}
24
25// ch initializes the m.c field if needed and returns it.
26func ch(m *Mutex) chan int {
27    <-g
28    defer func() {
29        g <- 1
30    }()
31    if m.c == nil {
32        m.c = make(chan int1)
33        m.c <- 1
34    }
35    return m.c
36}
37
MembersX
Mutex.Lock
Mutex.Lock.c
Mutex.Unlock
Mutex.Unlock.c
ch.m
Mutex
Mutex.c
Mutex.Lock.m
Mutex.Unlock.m
init
ch
Members
X