File tree 4 files changed +5
-105
lines changed
4 files changed +5
-105
lines changed Original file line number Diff line number Diff line change 45
45
fetch-depth : 0
46
46
- uses : actions/setup-go@v2
47
47
with :
48
- go-version : 1.17
48
+ go-version : 1.18
49
49
- run : tools/go_branch.sh
50
50
- run : git checkout go && git clean -xf . && go build ./...
51
51
- if : github.event_name == 'push'
Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ go_test(
42
42
size = "small" ,
43
43
srcs = [
44
44
"gate_test.go" ,
45
- "mutex_test.go" ,
46
45
"rwmutex_test.go" ,
47
46
"seqcount_test.go" ,
48
47
],
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3
3
// Use of this source code is governed by a BSD-style
4
4
// license that can be found in the LICENSE file.
5
5
6
- //go:build go1.13 && !go1.21
7
- // +build go1.13,!go1.21
8
-
9
- // When updating the build constraint (above), check that syncMutex matches the
10
- // standard library sync.Mutex definition.
11
-
12
6
package sync
13
7
14
8
import (
15
9
"sync"
16
- "sync/atomic"
17
10
"unsafe"
18
11
)
19
12
20
13
// CrossGoroutineMutex is equivalent to Mutex, but it need not be unlocked by a
21
14
// the same goroutine that locked the mutex.
22
15
type CrossGoroutineMutex struct {
23
- sync.Mutex
24
- }
25
-
26
- type syncMutex struct {
27
- state int32
28
- sema uint32
29
- }
30
-
31
- func (m * CrossGoroutineMutex ) state () * int32 {
32
- return & (* syncMutex )(unsafe .Pointer (& m .Mutex )).state
16
+ m sync.Mutex
33
17
}
34
18
35
19
// Lock locks the underlying Mutex.
36
20
// +checklocksignore
37
21
func (m * CrossGoroutineMutex ) Lock () {
38
- m .Mutex .Lock ()
22
+ m .m .Lock ()
39
23
}
40
24
41
25
// Unlock unlocks the underlying Mutex.
42
26
// +checklocksignore
43
27
func (m * CrossGoroutineMutex ) Unlock () {
44
- m .Mutex .Unlock ()
28
+ m .m .Unlock ()
45
29
}
46
30
47
- const (
48
- mutexUnlocked = 0
49
- mutexLocked = 1
50
- )
51
-
52
31
// TryLock tries to acquire the mutex. It returns true if it succeeds and false
53
32
// otherwise. TryLock does not block.
54
33
func (m * CrossGoroutineMutex ) TryLock () bool {
55
- if atomic .CompareAndSwapInt32 (m .state (), mutexUnlocked , mutexLocked ) {
56
- if RaceEnabled {
57
- RaceAcquire (unsafe .Pointer (& m .Mutex ))
58
- }
59
- return true
60
- }
61
- return false
34
+ return m .m .TryLock ()
62
35
}
63
36
64
37
// Mutex is a mutual exclusion lock. The zero value for a Mutex is an unlocked
You can’t perform that action at this time.
0 commit comments