LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #define MAXALIGN 8 | 5 #define MAXALIGN 8 |
6 | 6 |
7 typedef struct WaitQ WaitQ; | 7 typedef struct WaitQ WaitQ; |
8 typedef struct SudoG SudoG; | |
9 typedef struct Select Select; | 8 typedef struct Select Select; |
10 typedef struct Scase Scase; | 9 typedef struct Scase Scase; |
11 | |
12 struct SudoG | |
13 { | |
14 G* g; | |
15 uint32* selectdone; | |
16 SudoG* link; | |
17 int64 releasetime; | |
18 byte* elem; // data element | |
19 }; | |
20 | 10 |
21 struct WaitQ | 11 struct WaitQ |
22 { | 12 { |
23 SudoG* first; | 13 SudoG* first; |
24 SudoG* last; | 14 SudoG* last; |
25 }; | 15 }; |
26 | 16 |
27 // The garbage collector is assuming that Hchan can only contain pointers into t
he stack | |
28 // and cannot contain pointers into the heap. | |
29 struct Hchan | 17 struct Hchan |
30 { | 18 { |
31 uintgo qcount; // total data in the q | 19 uintgo qcount; // total data in the q |
32 uintgo dataqsiz; // size of the circular q | 20 uintgo dataqsiz; // size of the circular q |
| 21 byte* buf; |
33 uint16 elemsize; | 22 uint16 elemsize; |
34 uint32 closed; | 23 uint32 closed; |
35 Type* elemtype; // element type | 24 Type* elemtype; // element type |
36 uintgo sendx; // send index | 25 uintgo sendx; // send index |
37 uintgo recvx; // receive index | 26 uintgo recvx; // receive index |
38 WaitQ recvq; // list of recv waiters | 27 WaitQ recvq; // list of recv waiters |
39 WaitQ sendq; // list of send waiters | 28 WaitQ sendq; // list of send waiters |
40 » Lock; | 29 » Lock» lock; |
41 }; | 30 }; |
42 | 31 |
43 // Buffer follows Hchan immediately in memory. | 32 // Buffer follows Hchan immediately in memory. |
44 // chanbuf(c, i) is pointer to the i'th slot in the buffer. | 33 // chanbuf(c, i) is pointer to the i'th slot in the buffer. |
45 #define chanbuf(c, i) ((byte*)((c)+1)+(uintptr)(c)->elemsize*(i)) | 34 #define chanbuf(c, i) ((byte*)((c)->buf)+(uintptr)(c)->elemsize*(i)) |
46 | 35 |
47 enum | 36 enum |
48 { | 37 { |
49 debug = 0, | 38 debug = 0, |
50 | 39 |
51 // Scase.kind | 40 // Scase.kind |
52 CaseRecv, | 41 CaseRecv, |
53 CaseSend, | 42 CaseSend, |
54 CaseDefault, | 43 CaseDefault, |
55 }; | 44 }; |
56 | 45 |
| 46 // Known to compiler. |
| 47 // Changes here must also be made in src/cmd/gc/select.c's selecttype. |
57 struct Scase | 48 struct Scase |
58 { | 49 { |
59 SudoG sg; // must be first member (cast to Scase) | 50 SudoG sg; // must be first member (cast to Scase) |
60 Hchan* chan; // chan | 51 Hchan* chan; // chan |
61 byte* pc; // return pc | 52 byte* pc; // return pc |
62 uint16 kind; | 53 uint16 kind; |
63 uint16 so; // vararg of selected bool | 54 uint16 so; // vararg of selected bool |
64 bool* receivedp; // pointer to received bool (recv2) | 55 bool* receivedp; // pointer to received bool (recv2) |
65 }; | 56 }; |
66 | 57 |
| 58 // Known to compiler. |
| 59 // Changes here must also be made in src/cmd/gc/select.c's selecttype. |
67 struct Select | 60 struct Select |
68 { | 61 { |
69 uint16 tcase; // total count of scase[] | 62 uint16 tcase; // total count of scase[] |
70 uint16 ncase; // currently filled scase[] | 63 uint16 ncase; // currently filled scase[] |
71 uint16* pollorder; // case poll order | 64 uint16* pollorder; // case poll order |
72 Hchan** lockorder; // channel lock order | 65 Hchan** lockorder; // channel lock order |
73 Scase scase[1]; // one per case (in order of appearance) | 66 Scase scase[1]; // one per case (in order of appearance) |
74 }; | 67 }; |
LEFT | RIGHT |