-
Notifications
You must be signed in to change notification settings - Fork 12
/
rxDataset.go
74 lines (58 loc) · 1.34 KB
/
rxDataset.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package randomx
import "C"
import (
"fmt"
"sync"
)
func NewRxDataset(flags ...Flag) (*RxDataset, error) {
cache, err := NewRxCache(flags...)
if err != nil {
return nil, err
}
dataset, err := AllocDataset(flags...)
if err != nil {
return nil, err
}
return &RxDataset{
dataset: dataset,
rxCache: cache,
workerNum: 1,
}, nil
}
func (ds *RxDataset) Close() {
if ds.dataset != nil {
ReleaseDataset(ds.dataset)
}
ds.rxCache.Close()
}
func (ds *RxDataset) GoInit(seed []byte, workerNum uint32) bool {
if ds.rxCache.Init(seed) == false {
fmt.Println("WARN: rxCache has already been initialized by the same seed")
}
if ds.rxCache == nil || ds.rxCache.cache == nil {
return false
}
datasetItemCount := DatasetItemCount()
var wg sync.WaitGroup
for i := uint32(0); i < workerNum; i++ {
a := (datasetItemCount * i) / workerNum
b := (datasetItemCount * (i + 1)) / workerNum
wg.Add(1)
go func() {
InitDataset(ds.dataset, ds.rxCache.cache, a, b-a)
wg.Done()
}()
}
wg.Wait()
return true
}
func (ds *RxDataset) CInit(seed []byte, workerNum uint32) bool {
if ds.rxCache.Init(seed) == false {
fmt.Println("WARN: rxCache has already been initialized by the same seed")
}
if ds.rxCache == nil || ds.rxCache.cache == nil {
return false
}
FastInitFullDataset(ds.dataset, ds.rxCache.cache, workerNum)
return true
}