Skip to content

Commit

Permalink
runtime,reflect: merge select* const into internal/abi
Browse files Browse the repository at this point in the history
For golang#59670

Change-Id: I48a6fca4154591bef8df4364230295e826bd8730
  • Loading branch information
qiulaidongfeng committed Jan 30, 2024
1 parent 4afb155 commit 0b292b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 10 additions & 0 deletions src/internal/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,16 @@ const (
TraceArgsMaxLen = (TraceArgsMaxDepth*3+2)*TraceArgsLimit + 1
)

// A SelectDir describes the communication direction of a select case.
type SelectDir int

const (
_ SelectDir = iota
SelectSend // case Chan <- Send
SelectRecv // case <-Chan:
SelectDefault // default
)

// Populate the data.
// The data is a stream of bytes, which contains the offsets and sizes of the
// non-aggregate arguments or non-aggregate fields/elements of aggregate-typed
Expand Down
8 changes: 4 additions & 4 deletions src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -3038,15 +3038,15 @@ type runtimeSelect struct {
func rselect([]runtimeSelect) (chosen int, recvOK bool)

// A SelectDir describes the communication direction of a select case.
type SelectDir int
type SelectDir = abi.SelectDir

// NOTE: These values must match ../runtime/select.go:/selectDir.

const (
_ SelectDir = iota
SelectSend // case Chan <- Send
SelectRecv // case <-Chan:
SelectDefault // default
SelectSend = abi.SelectSend // case Chan <- Send
SelectRecv = abi.SelectRecv // case <-Chan:
SelectDefault = abi.SelectDefault // default
)

// A SelectCase describes a single case in a select operation.
Expand Down
18 changes: 4 additions & 14 deletions src/runtime/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,12 @@ func (c *hchan) sortkey() uintptr {
// A runtimeSelect is a single case passed to rselect.
// This must match ../reflect/value.go:/runtimeSelect
type runtimeSelect struct {
dir selectDir
dir abi.SelectDir
typ unsafe.Pointer // channel type (not used here)
ch *hchan // channel
val unsafe.Pointer // ptr to data (SendDir) or ptr to receive buffer (RecvDir)
}

// These values must match ../reflect/value.go:/SelectDir.
type selectDir int

const (
_ selectDir = iota
selectSend // case Chan <- Send
selectRecv // case <-Chan:
selectDefault // default
)

//go:linkname reflect_rselect reflect.rselect
func reflect_rselect(cases []runtimeSelect) (int, bool) {
if len(cases) == 0 {
Expand All @@ -550,13 +540,13 @@ func reflect_rselect(cases []runtimeSelect) (int, bool) {
for i, rc := range cases {
var j int
switch rc.dir {
case selectDefault:
case abi.SelectDefault:
dflt = i
continue
case selectSend:
case abi.SelectSend:
j = nsends
nsends++
case selectRecv:
case abi.SelectRecv:
nrecvs++
j = len(cases) - nrecvs
}
Expand Down

0 comments on commit 0b292b6

Please sign in to comment.