Rebase.
[official-gcc.git] / libgo / runtime / chan.h
blob70b0b9d90903cc1b8a84dda6ee3bcd9ed23ba78a
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
22 struct WaitQ
24 SudoG* first;
25 SudoG* last;
28 // The garbage collector is assuming that Hchan can only contain pointers into the stack
29 // and cannot contain pointers into the heap.
30 struct Hchan
32 uintgo qcount; // total data in the q
33 uintgo dataqsiz; // size of the circular q
34 uint16 elemsize;
35 uint16 pad; // ensures proper alignment of the buffer that follows Hchan in memory
36 bool closed;
37 const Type* elemtype; // element type
38 uintgo sendx; // send index
39 uintgo recvx; // receive index
40 WaitQ recvq; // list of recv waiters
41 WaitQ sendq; // list of send waiters
42 Lock;
45 // Buffer follows Hchan immediately in memory.
46 // chanbuf(c, i) is pointer to the i'th slot in the buffer.
47 #define chanbuf(c, i) ((byte*)((c)+1)+(uintptr)(c)->elemsize*(i))
49 enum
51 debug = 0,
53 // Scase.kind
54 CaseRecv,
55 CaseSend,
56 CaseDefault,
59 struct Scase
61 SudoG sg; // must be first member (cast to Scase)
62 Hchan* chan; // chan
63 uint16 kind;
64 uint16 index; // index to return
65 bool* receivedp; // pointer to received bool (recv2)
68 struct Select
70 uint16 tcase; // total count of scase[]
71 uint16 ncase; // currently filled scase[]
72 uint16* pollorder; // case poll order
73 Hchan** lockorder; // channel lock order
74 Scase scase[1]; // one per case (in order of appearance)