github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/runtime/chan1.go (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  package runtime
     6  
     7  import "unsafe"
     8  
     9  //#define	MAXALIGN	8
    10  
    11  type waitq struct {
    12  	first *sudog
    13  	last  *sudog
    14  }
    15  
    16  type hchan struct {
    17  	qcount   uint // total data in the q
    18  	dataqsiz uint // size of the circular q
    19  	buf      *byte
    20  	elemsize uint16
    21  	closed   uint32
    22  	elemtype *_type // element type
    23  	sendx    uint   // send index
    24  	recvx    uint   // receive index
    25  	recvq    waitq  // list of recv waiters
    26  	sendq    waitq  // list of send waiters
    27  	lock     mutex
    28  }
    29  
    30  // Buffer follows Hchan immediately in memory.
    31  // chanbuf(c, i) is pointer to the i'th slot in the buffer.
    32  // #define chanbuf(c, i) ((byte*)((c)->buf)+(uintptr)(c)->elemsize*(i))
    33  
    34  const (
    35  	// scase.kind
    36  	_CaseRecv = iota
    37  	_CaseSend
    38  	_CaseDefault
    39  )
    40  
    41  // Known to compiler.
    42  // Changes here must also be made in src/cmd/gc/select.c's selecttype.
    43  type scase struct {
    44  	elem        unsafe.Pointer // data element
    45  	_chan       *hchan         // chan
    46  	pc          uintptr        // return pc
    47  	kind        uint16
    48  	so          uint16 // vararg of selected bool
    49  	receivedp   *bool  // pointer to received bool (recv2)
    50  	releasetime int64
    51  }
    52  
    53  // Known to compiler.
    54  // Changes here must also be made in src/cmd/gc/select.c's selecttype.
    55  type _select struct {
    56  	tcase     uint16   // total count of scase[]
    57  	ncase     uint16   // currently filled scase[]
    58  	pollorder *uint16  // case poll order
    59  	lockorder **hchan  // channel lock order
    60  	scase     [1]scase // one per case (in order of appearance)
    61  }