github.com/primecitizens/pcz/std@v0.2.1/builtin/go/chan.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2014 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  package stdgo
     9  
    10  import (
    11  	"unsafe"
    12  
    13  	"github.com/primecitizens/pcz/std/core/abi"
    14  )
    15  
    16  type Chan struct {
    17  	Qcount    uint           // total data in the queue
    18  	DataqSize uint           // size of the circular queue
    19  	Buf       unsafe.Pointer // points to an array of dataqsiz elements
    20  	ElemSize  uint16
    21  	Closed    uint32
    22  	ElemType  *abi.Type // element type
    23  	Sendx     uint      // send index
    24  	Recvx     uint      // receive index
    25  
    26  	// NOTE: linker checks `recvq` and `sendq` field for dwarf
    27  	// 		DO NOT CHANGE THESE NAMES
    28  	recvq waitq // list of recv waiters
    29  	sendq waitq // list of send waiters
    30  
    31  	// Lock protects all fields in hchan, as well as several
    32  	// fields in sudogs blocked on this channel.
    33  	//
    34  	// Do not change another G's status while holding this Lock
    35  	// (in particular, do not ready a G), as this can deadlock
    36  	// with stack shrinking.
    37  	Lock Mutex
    38  }
    39  
    40  type Waitq struct {
    41  	// NOTE: linker checks `first` and `last` field for dwarf
    42  	// 		DO NOT CHANGE THESE NAMES
    43  	first *Sudog
    44  	last  *Sudog
    45  }
    46  
    47  func MakeChan(chanType *abi.ChanType, sz int) *hchan {
    48  	return nil
    49  }
    50  
    51  // Recv receives on channel c and writes the received data to ep.
    52  //
    53  // ep may be nil, in which case received data is ignored.
    54  //
    55  // If block == false and no elements are available, returns (false, false).
    56  // Otherwise, if c is closed, zeros *ep and returns (true, false).
    57  // Otherwise, fills in *ep with an element and returns (true, true).
    58  // A non-nil ep must point to the heap or the caller's stack.
    59  //
    60  //go:nosplit
    61  func Recv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool) {
    62  	return
    63  }
    64  
    65  // generic single channel send
    66  //
    67  // If block is not nil, then the protocol will not sleep but return if it could
    68  // not complete.
    69  //
    70  // sleep can wake up with g.param == nil when a channel involved in the sleep
    71  // has been closed. it is easiest to loop and re-run the operation;
    72  // we'll see that it's now closed.
    73  //
    74  //go:nosplit
    75  func Send(c *hchan, elem unsafe.Pointer, block bool, callerpc uintptr) bool {
    76  	return false
    77  }
    78  
    79  // Select case descriptor.
    80  // Known to compiler.
    81  // Changes here must also be made in src/cmd/compile/internal/walk/select.go's scasetype.
    82  type SelectCase struct {
    83  	C    *hchan         // chan
    84  	Elem unsafe.Pointer // data element
    85  }
    86  
    87  // Select implements the select statement.
    88  //
    89  // cas0 points to an array of type [ncases]scase, and order0 points to
    90  // an array of type [2*ncases]uint16 where ncases must be <= 65536.
    91  // Both reside on the goroutine's stack (regardless of any escaping in
    92  // Select).
    93  //
    94  // For race detector builds, pc0 points to an array of type
    95  // [ncases]uintptr (also on the stack); for other builds, it's set to
    96  // nil.
    97  //
    98  // Select returns the index of the chosen scase, which matches the
    99  // ordinal position of its respective select{recv,send,default} call.
   100  // Also, if the chosen scase was a receive operation, it reports whether
   101  // a value was received.
   102  func Select(cas0 *SelectCase, order0 *uint16, pc0 *uintptr, nsends, nrecvs int, block bool) (int, bool) {
   103  	return 0, false
   104  }
   105  
   106  func Block() {
   107  	// TODO: Park
   108  }
   109  
   110  func CloseChan(c *hchan) {}
   111  
   112  func Recover(argp uintptr) any {
   113  	// TODO
   114  	return nil
   115  }