github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xsync/xatomic/atomic_string.go (about)

     1  package xatomic
     2  
     3  import (
     4  	"sync/atomic"
     5  )
     6  
     7  type AtomicString struct {
     8  	v atomic.Value
     9  }
    10  
    11  func NewAtomicString(str string) *AtomicString {
    12  	v := atomic.Value{}
    13  	v.Store(str)
    14  	return &AtomicString{v: v}
    15  }
    16  
    17  func (s *AtomicString) Load() string {
    18  	return s.v.Load().(string)
    19  }
    20  
    21  func (s *AtomicString) Store(str string) {
    22  	s.v.Store(str)
    23  }