github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/runtime/chan.h (about)

     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.
     4  
     5  typedef	struct	WaitQ	WaitQ;
     6  typedef	struct	SudoG	SudoG;
     7  typedef	struct	Select	Select;
     8  typedef	struct	Scase	Scase;
     9  
    10  typedef struct	__go_type_descriptor	Type;
    11  typedef struct	__go_channel_type	ChanType;
    12  
    13  struct	SudoG
    14  {
    15  	G*	g;
    16  	uint32*	selectdone;
    17  	SudoG*	link;
    18  	int64	releasetime;
    19  	byte*	elem;		// data element
    20  };
    21  
    22  struct	WaitQ
    23  {
    24  	SudoG*	first;
    25  	SudoG*	last;
    26  };
    27  
    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
    31  {
    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	lock;
    43  };
    44  
    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))
    48  
    49  enum
    50  {
    51  	debug = 0,
    52  
    53  	// Scase.kind
    54  	CaseRecv,
    55  	CaseSend,
    56  	CaseDefault,
    57  };
    58  
    59  struct	Scase
    60  {
    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)
    66  };
    67  
    68  struct	Select
    69  {
    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)
    75  };