-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblockstm.go
48 lines (35 loc) · 1.11 KB
/
blockstm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package blockstm
import "context"
type PropertyCheck func(*ParallelExecutor) error
func executeParallelWithCheck(interruptCtx context.Context, tasks []ExecTask, profile bool, check PropertyCheck, metadata bool, numProcs int) (result ParallelExecutionResult, err error) {
if len(tasks) == 0 {
return ParallelExecutionResult{MakeTxnInputOutput(len(tasks)), nil, nil, nil}, nil
}
pe := NewParallelExecutor(tasks, profile, metadata, numProcs)
err = pe.Prepare()
if err != nil {
pe.Close(true)
return
}
for range pe.chResults {
if interruptCtx != nil && interruptCtx.Err() != nil {
pe.Close(true)
return result, interruptCtx.Err()
}
res := pe.resultQueue.Pop()
result, err = pe.Step(&res)
if err != nil {
return result, err
}
if check != nil {
err = check(pe)
}
if result.TxIO != nil || err != nil {
return result, err
}
}
return
}
func ExecuteParallel(interruptCtx context.Context, tasks []ExecTask, profile bool, metadata bool, numProcs int) (result ParallelExecutionResult, err error) {
return executeParallelWithCheck(interruptCtx, tasks, profile, nil, metadata, numProcs)
}