@@ -112,8 +112,8 @@ type DB struct {
112112 flushChan chan flushTask // For flushing memtables.
113113 closeOnce sync.Once // For closing DB only once.
114114
115- blockWrites int32
116- isClosed uint32
115+ blockWrites atomic. Int32
116+ isClosed atomic. Uint32
117117
118118 orc * oracle
119119 bannedNamespaces * lockedKeys
@@ -531,16 +531,16 @@ func (db *DB) Close() error {
531531// IsClosed denotes if the badger DB is closed or not. A DB instance should not
532532// be used after closing it.
533533func (db * DB ) IsClosed () bool {
534- return atomic . LoadUint32 ( & db .isClosed ) == 1
534+ return db .isClosed . Load ( ) == 1
535535}
536536
537537func (db * DB ) close () (err error ) {
538538 defer db .allocPool .Release ()
539539
540540 db .opt .Debugf ("Closing database" )
541- db .opt .Infof ("Lifetime L0 stalled for: %s\n " , time .Duration (atomic . LoadInt64 ( & db .lc .l0stallsMs )))
541+ db .opt .Infof ("Lifetime L0 stalled for: %s\n " , time .Duration (db .lc .l0stallsMs . Load ( )))
542542
543- atomic . StoreInt32 ( & db .blockWrites , 1 )
543+ db .blockWrites . Store ( 1 )
544544
545545 if ! db .opt .InMemory {
546546 // Stop value GC first.
@@ -626,7 +626,7 @@ func (db *DB) close() (err error) {
626626 db .blockCache .Close ()
627627 db .indexCache .Close ()
628628
629- atomic . StoreUint32 ( & db .isClosed , 1 )
629+ db .isClosed . Store ( 1 )
630630 db .threshold .close ()
631631
632632 if db .opt .InMemory {
@@ -851,7 +851,7 @@ func (db *DB) writeRequests(reqs []*request) error {
851851}
852852
853853func (db * DB ) sendToWriteCh (entries []* Entry ) (* request , error ) {
854- if atomic . LoadInt32 ( & db .blockWrites ) == 1 {
854+ if db .blockWrites . Load ( ) == 1 {
855855 return nil , ErrBlockedWrites
856856 }
857857 var count , size int64
@@ -1604,7 +1604,7 @@ func (db *DB) Flatten(workers int) error {
16041604
16051605func (db * DB ) blockWrite () error {
16061606 // Stop accepting new writes.
1607- if ! atomic . CompareAndSwapInt32 ( & db .blockWrites , 0 , 1 ) {
1607+ if ! db .blockWrites . CompareAndSwap ( 0 , 1 ) {
16081608 return ErrBlockedWrites
16091609 }
16101610
@@ -1619,7 +1619,7 @@ func (db *DB) unblockWrite() {
16191619 go db .doWrites (db .closers .writes )
16201620
16211621 // Resume writes.
1622- atomic . StoreInt32 ( & db .blockWrites , 0 )
1622+ db .blockWrites . Store ( 0 )
16231623}
16241624
16251625func (db * DB ) prepareToDrop () (func (), error ) {
@@ -1709,7 +1709,7 @@ func (db *DB) dropAll() (func(), error) {
17091709 if err != nil {
17101710 return resume , err
17111711 }
1712- db .lc .nextFileID = 1
1712+ db .lc .nextFileID . Store ( 1 )
17131713 db .opt .Infof ("Deleted %d value log files. DropAll done.\n " , num )
17141714 db .blockCache .Clear ()
17151715 db .indexCache .Clear ()
@@ -1906,7 +1906,7 @@ func (db *DB) Subscribe(ctx context.Context, cb func(kv *KVList) error, matches
19061906 return err
19071907 case <- ctx .Done ():
19081908 c .Done ()
1909- atomic . StoreUint64 ( s .active , 0 )
1909+ s .active . Store ( 0 )
19101910 drain ()
19111911 db .pub .deleteSubscriber (s .id )
19121912 // Delete the subscriber to avoid further updates.
@@ -1915,7 +1915,7 @@ func (db *DB) Subscribe(ctx context.Context, cb func(kv *KVList) error, matches
19151915 err := slurp (batch )
19161916 if err != nil {
19171917 c .Done ()
1918- atomic . StoreUint64 ( s .active , 0 )
1918+ s .active . Store ( 0 )
19191919 drain ()
19201920 // Delete the subscriber if there is an error by the callback.
19211921 db .pub .deleteSubscriber (s .id )
0 commit comments