2016-10-07 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / libgo / runtime / chan.h
blob473f365b921836e183f0c1d93451aff21780eaf7
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 typedef struct WaitQ WaitQ;
6 typedef struct SudoG SudoG;
7 typedef struct Select Select;
8 typedef struct Scase Scase;
10 typedef struct __go_type_descriptor Type;
11 typedef struct __go_channel_type ChanType;
13 struct SudoG
15 G* g;
16 uint32* selectdone;
17 SudoG* link;
18 int64 releasetime;
19 byte* elem; // data element
20 uint32 ticket;
23 struct WaitQ
25 SudoG* first;
26 SudoG* last;
29 // The garbage collector is assuming that Hchan can only contain pointers into the stack
30 // and cannot contain pointers into the heap.
31 struct Hchan
33 uintgo qcount; // total data in the q
34 uintgo dataqsiz; // size of the circular q
35 uint16 elemsize;
36 uint16 pad; // ensures proper alignment of the buffer that follows Hchan in memory
37 bool closed;
38 const Type* elemtype; // element type
39 uintgo sendx; // send index
40 uintgo recvx; // receive index
41 WaitQ recvq; // list of recv waiters
42 WaitQ sendq; // list of send waiters
43 Lock;
46 // Buffer follows Hchan immediately in memory.
47 // chanbuf(c, i) is pointer to the i'th slot in the buffer.
48 #define chanbuf(c, i) ((byte*)((c)+1)+(uintptr)(c)->elemsize*(i))
50 enum
52 debug = 0,
54 // Scase.kind
55 CaseRecv,
56 CaseSend,
57 CaseDefault,
60 struct Scase
62 SudoG sg; // must be first member (cast to Scase)
63 Hchan* chan; // chan
64 uint16 kind;
65 uint16 index; // index to return
66 bool* receivedp; // pointer to received bool (recv2)
69 struct Select
71 uint16 tcase; // total count of scase[]
72 uint16 ncase; // currently filled scase[]
73 uint16* pollorder; // case poll order
74 Hchan** lockorder; // channel lock order
75 Scase scase[1]; // one per case (in order of appearance)