Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc.questionFlags: Add .Contains() method #439

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion rpc/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const (
finishSent
)

// flags.Contains(flag) Returns true iff flags contains flag, which must
// be a single flag.
func (flags questionFlags) Contains(flag questionFlags) bool {
return flags&flag != 0
}

// newQuestion adds a new question to c's table.
func (c *lockedConn) newQuestion(method capnp.Method) *question {
q := &question{
Expand Down Expand Up @@ -110,7 +116,7 @@ func (q *question) handleCancel(ctx context.Context) {

q.c.withLocked(func(c *lockedConn) {
// Promise already fulfilled?
if q.flags&finished != 0 {
if q.flags.Contains(finished) {
return
}
q.flags |= finished
Expand Down
8 changes: 4 additions & 4 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (c *lockedConn) releaseAnswers(rl *releaseList, answers map[answerID]*answe

func (c *lockedConn) releaseQuestions(rl *releaseList, questions []*question) {
for _, q := range questions {
canceled := q != nil && q.flags&finished != 0
canceled := q != nil && q.flags.Contains(finished)
if !canceled {
// Only reject the question if it isn't already flagged
// as finished; otherwise it was rejected when the finished
Expand Down Expand Up @@ -1085,15 +1085,15 @@ func (c *Conn) handleReturn(ctx context.Context, ret rpccp.Return, release capnp
"incoming return: question " + str.Utod(qid) + " does not exist",
))
}
canceled := q.flags&finished != 0
canceled := q.flags.Contains(finished)
q.flags |= finished
if canceled {
// Wait for cancelation task to write the Finish message. If the
// Finish message could not be sent to the remote vat, we can't
// reuse the ID.
select {
case <-q.finishMsgSend:
if q.flags&finishSent != 0 {
if q.flags.Contains(finishSent) {
c.lk.questionID.remove(uint32(qid))
}
rl.Add(release)
Expand All @@ -1104,7 +1104,7 @@ func (c *Conn) handleReturn(ctx context.Context, ret rpccp.Return, release capnp
c := unlockedConn
<-q.finishMsgSend
c.withLocked(func(c *lockedConn) {
if q.flags&finishSent != 0 {
if q.flags.Contains(finishSent) {
c.lk.questionID.remove(uint32(qid))
}
})
Expand Down