@@ -163,7 +163,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
163163 rows := int (size ) / hashBytes
164164
165165 // Start a monitoring goroutine to report progress on low end devices
166- var progress uint32
166+ var progress atomic. Uint32
167167
168168 done := make (chan struct {})
169169 defer close (done )
@@ -174,7 +174,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
174174 case <- done :
175175 return
176176 case <- time .After (3 * time .Second ):
177- logger .Info ("Generating ethash verification cache" , "percentage" , atomic . LoadUint32 ( & progress )* 100 / uint32 (rows )/ (cacheRounds + 1 ), "elapsed" , common .PrettyDuration (time .Since (start )))
177+ logger .Info ("Generating ethash verification cache" , "percentage" , progress . Load ( )* 100 / uint32 (rows )/ (cacheRounds + 1 ), "elapsed" , common .PrettyDuration (time .Since (start )))
178178 }
179179 }
180180 }()
@@ -185,7 +185,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
185185 keccak512 (cache , seed )
186186 for offset := uint64 (hashBytes ); offset < size ; offset += hashBytes {
187187 keccak512 (cache [offset :], cache [offset - hashBytes :offset ])
188- atomic . AddUint32 ( & progress , 1 )
188+ progress . Add ( 1 )
189189 }
190190 // Use a low-round version of randmemohash
191191 temp := make ([]byte , hashBytes )
@@ -200,7 +200,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
200200 bitutil .XORBytes (temp , cache [srcOff :srcOff + hashBytes ], cache [xorOff :xorOff + hashBytes ])
201201 keccak512 (cache [dstOff :], temp )
202202
203- atomic . AddUint32 ( & progress , 1 )
203+ progress . Add ( 1 )
204204 }
205205 }
206206 // Swap the byte order on big endian systems and return
@@ -299,7 +299,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
299299 var pend sync.WaitGroup
300300 pend .Add (threads )
301301
302- var progress uint64
302+ var progress atomic. Uint64
303303 for i := 0 ; i < threads ; i ++ {
304304 go func (id int ) {
305305 defer pend .Done ()
@@ -323,7 +323,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
323323 }
324324 copy (dataset [index * hashBytes :], item )
325325
326- if status := atomic . AddUint64 ( & progress , 1 ); status % percent == 0 {
326+ if status := progress . Add ( 1 ); status % percent == 0 {
327327 logger .Info ("Generating DAG in progress" , "percentage" , (status * 100 )/ (size / hashBytes ), "elapsed" , common .PrettyDuration (time .Since (start )))
328328 }
329329 }
0 commit comments