Created
March 29, 2019 13:25
-
-
Save draveness/88c8a7a17f1be1ca22b79021c16f40f6 to your computer and use it in GitHub Desktop.
selectgo loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func selectgo(cas0 *scase, order0 *uint16, ncases int) (int, bool) { | |
// ... | |
loop: | |
// ... | |
for i := 0; i < ncases; i++ { | |
casi = int(pollorder[i]) | |
cas = &scases[casi] | |
c = cas.c | |
switch cas.kind { | |
case caseNil: | |
continue | |
case caseRecv: | |
sg = c.sendq.dequeue() | |
if sg != nil { | |
goto recv | |
} | |
if c.qcount > 0 { | |
goto bufrecv | |
} | |
if c.closed != 0 { | |
goto rclose | |
} | |
case caseSend: | |
if c.closed != 0 { | |
goto sclose | |
} | |
sg = c.recvq.dequeue() | |
if sg != nil { | |
goto send | |
} | |
if c.qcount < c.dataqsiz { | |
goto bufsend | |
} | |
case caseDefault: | |
dfli = casi | |
dfl = cas | |
} | |
} | |
if dfl != nil { | |
selunlock(scases, lockorder) | |
casi = dfli | |
cas = dfl | |
goto retc | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
浅谈 Go 语言 select 的实现原理