File tree 6 files changed +73
-12
lines changed
6 files changed +73
-12
lines changed Original file line number Diff line number Diff line change 1
- // This package supports the implementation of the qml package,
2
- // and must not be used by itself.
1
+ // Package cdata supports the implementation of the qml package.
3
2
package cdata
4
3
5
4
func Ref () uintptr
Original file line number Diff line number Diff line change
1
+ // +build !go1.4
2
+
1
3
#include "runtime.h"
2
4
3
5
void ·Ref (uintptr ref ) {
Original file line number Diff line number Diff line change
1
+ // +build go1.4
2
+
3
+ #include "textflag.h"
4
+
5
+ TEXT ·Ref(SB),NOSPLIT,$4 -4
6
+ CALL runtime·acquirem(SB)
7
+ MOVL 0 (SP), AX
8
+ MOVL AX, ret +0 (FP)
9
+ CALL runtime·releasem(SB)
10
+ RET
11
+
12
+ TEXT ·Addrs(SB),NOSPLIT,$0 -8
13
+ MOVL $runtime·main(SB), AX
14
+ MOVL AX, ret +0 (FP)
15
+ MOVL $runtime·main_main(SB), AX
16
+ MOVL AX, ret +8 (FP)
17
+ RET
Original file line number Diff line number Diff line change
1
+ // +build go1.4
2
+
3
+ #include "textflag.h"
4
+
5
+ TEXT ·Ref(SB),NOSPLIT,$8 -8
6
+ CALL runtime·acquirem(SB)
7
+ MOVQ 0 (SP), AX
8
+ MOVQ AX, ret +0 (FP)
9
+ CALL runtime·releasem(SB)
10
+ RET
11
+
12
+ TEXT ·Addrs(SB),NOSPLIT,$0 -16
13
+ MOVQ $runtime·main(SB), AX
14
+ MOVQ AX, ret +0 (FP)
15
+ MOVQ $runtime·main_main(SB), AX
16
+ MOVQ AX, ret +8 (FP)
17
+ RET
Original file line number Diff line number Diff line change
1
+ // +build go1.4
2
+
3
+ #include "textflag.h"
4
+
5
+ TEXT ·Ref(SB),NOSPLIT,$4 -4
6
+ BL runtime·acquirem(SB)
7
+ MOVW 4 (R13), R0
8
+ MOVW R0, ret +0 (FP)
9
+ MOVW R0, 4 (R13)
10
+ BL runtime·releasem(SB)
11
+ RET
12
+
13
+ TEXT ·Addrs(SB),NOSPLIT,$0 -8
14
+ MOVW $runtime·main(SB), R0
15
+ MOVW R0, ret +0 (FP)
16
+ MOVW $runtime·main_main(SB), R0
17
+ MOVW R0, ret +4 (FP)
18
+ RET
Original file line number Diff line number Diff line change @@ -6,29 +6,37 @@ import (
6
6
"testing"
7
7
)
8
8
9
+ type refPair struct {
10
+ ref1 , ref2 uintptr
11
+ }
12
+
9
13
func TestRef (t * testing.T ) {
10
14
const N = 10
11
15
runtime .LockOSThread ()
16
+ exit := sync.WaitGroup {}
17
+ exit .Add (1 )
18
+ defer exit .Done ()
12
19
wg := sync.WaitGroup {}
13
20
wg .Add (N )
14
- ch := make (chan uintptr )
21
+ ch := make (chan refPair )
15
22
for i := 0 ; i < N ; i ++ {
16
23
go func () {
17
24
runtime .LockOSThread ()
18
25
wg .Done ()
19
- ch <- Ref ()
20
- wg .Wait ()
26
+ ch <- refPair { Ref (), Ref ()}
27
+ exit .Wait ()
21
28
}()
22
29
}
23
30
wg .Wait ()
24
- refs := [] uintptr { Ref ()}
31
+ refs := make ( map [ uintptr ] bool )
25
32
for i := 0 ; i < N ; i ++ {
26
- chref := <- ch
27
- for _ , ref := range refs {
28
- if chref == ref {
29
- t .Fatalf ("found duplicated ref: %d == %d" , chref , ref )
30
- }
33
+ pair := <- ch
34
+ if pair .ref1 != pair .ref2 {
35
+ t .Fatalf ("found inconsistent ref: %d != %d" , pair .ref1 , pair .ref2 )
36
+ }
37
+ if refs [pair .ref1 ] {
38
+ t .Fatalf ("found duplicated ref: %d" , pair .ref1 )
31
39
}
32
- refs = append ( refs , chref )
40
+ refs [ pair . ref1 ] = true
33
41
}
34
42
}
You can’t perform that action at this time.
0 commit comments