Skip to content

Commit

Permalink
fix: race with parallel calls to Inner (#64)
Browse files Browse the repository at this point in the history
* fix race

* fix? data race seen in test with debug output
  • Loading branch information
muir authored Apr 1, 2023
1 parent aaae50e commit 22f5e15
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func generateInputMapper(fm *provider, start int, param flowType, rmap map[typeC
return func(v valueCollection) []reflect.Value {
if debugEnabled() {
debugf("%s: %s [%s] numIn:%d, m:%v", fm, param, formatFlow(fm.flows[param]), pMap.len, pMap.vcIndex)
dumpValueArray(v, "", vmap)
}
dumpValueArray(v, "", vmap)
in := make([]reflect.Value, pMap.len)
for i := start; i < pMap.len; i++ {
if pMap.vcIndex[i] != -1 {
Expand Down Expand Up @@ -207,26 +207,26 @@ func generateWrappers(

// for thread safety, this is not built outside WrapWrapper
inner := func(i []reflect.Value) []reflect.Value {
common := func(v valueCollection) []reflect.Value {
outMap(v, i)
next(v)
r := retMap(v)
for i, retV := range r {
if rTypes[i].Kind() == reflect.Interface {
r[i] = retV.Convert(rTypes[i])
}
}
return r
}
if !fm.parallel {
callCount++
if callCount > 1 {
v = vCopy.Copy()
}
outMap(v, i)
next(v)
} else {
atomic.AddInt32(&callCount, 1)
vc := vCopy.Copy()
outMap(vc, i)
next(vc)
}
r := retMap(v)
for i, retV := range r {
if rTypes[i].Kind() == reflect.Interface {
r[i] = retV.Convert(rTypes[i])
}
return common(v)
}
return r
atomic.AddInt32(&callCount, 1)
return common(vCopy.Copy())
}
in := inMap(v)
if reflective {
Expand Down

0 comments on commit 22f5e15

Please sign in to comment.