Skip to content

Commit c355dd6

Browse files
laines-itoleg-jukovec
authored andcommitted
future: wrap fut.finished with mutex
Make race checker happier. Closes #521
1 parent 4460769 commit c355dd6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ func (conn *Connection) send(req Request, streamId uint64) *Future {
10371037

10381038
fut := conn.newFuture(req)
10391039

1040-
if fut.finished {
1040+
if fut.isFinished() {
10411041
conn.decrementRequestCnt()
10421042
return fut
10431043
}
@@ -1061,7 +1061,7 @@ func (conn *Connection) putFuture(fut *Future, req Request, streamId uint64) {
10611061
shard := &conn.shard[shardn]
10621062
shard.bufmut.Lock()
10631063

1064-
if fut.finished {
1064+
if fut.isFinished() {
10651065
shard.bufmut.Unlock()
10661066
return
10671067
}

future.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ func (fut *Future) finish() {
4242
fut.cond.Broadcast()
4343
}
4444

45+
func (fut *Future) isFinished() bool {
46+
fut.mutex.Lock()
47+
defer fut.mutex.Unlock()
48+
49+
return fut.finished
50+
}
51+
4552
// NewFuture creates a new empty Future for a given Request.
4653
func NewFuture(req Request) (fut *Future) {
4754
fut = &Future{}

0 commit comments

Comments
 (0)