本文整理匯總了Golang中sync/atomic.StorePointer函數的典型用法代碼示例。如果您正苦於以下問題:Golang StorePointer函數的具體用法?Golang StorePointer怎麽用?Golang StorePointer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了StorePointer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: seterr
// Set background error.
func (d *DB) seterr(err error) {
if err == nil {
atomic.StorePointer(&d.err, nil)
} else {
atomic.StorePointer(&d.err, unsafe.Pointer(&errWrap{err}))
}
}
示例2: Refresh
func (b *Bucket) Refresh() error {
pool := b.pool
tmpb := &Bucket{}
err := pool.client.parseURLResponse(b.URI, tmpb)
if err != nil {
return err
}
newcps := make([]*connectionPool, len(tmpb.VBSMJson.ServerList))
for i := range newcps {
if b.ah != nil {
newcps[i] = newConnectionPool(
tmpb.VBSMJson.ServerList[i],
b.ah, PoolSize, PoolOverflow)
} else {
newcps[i] = newConnectionPool(
tmpb.VBSMJson.ServerList[i],
b.authHandler(), PoolSize, PoolOverflow)
}
}
b.replaceConnPools(newcps)
tmpb.ah = b.ah
atomic.StorePointer(&b.vBucketServerMap, unsafe.Pointer(&tmpb.VBSMJson))
atomic.StorePointer(&b.nodeList, unsafe.Pointer(&tmpb.NodesJSON))
return nil
}
示例3: visitItems
func (p *partitionstore) visitItems(start []byte, withValue bool,
visitor func(*item) bool) (err error) {
keys, changes := p.colls()
var vErr error
v := func(kItem *gkvlite.Item) bool {
i := (*item)(atomic.LoadPointer(&kItem.Transient))
if i != nil {
return visitor(i)
}
var cItem *gkvlite.Item
cItem, vErr = changes.GetItem(kItem.Val, true)
if vErr != nil {
return false
}
if cItem == nil {
return true // TODO: track this case; might have been compacted away.
}
i = (*item)(atomic.LoadPointer(&cItem.Transient))
if i != nil {
atomic.StorePointer(&kItem.Transient, unsafe.Pointer(i))
return visitor(i)
}
i = &item{key: kItem.Key}
if vErr = i.fromValueBytes(cItem.Val); vErr != nil {
return false
}
atomic.StorePointer(&cItem.Transient, unsafe.Pointer(i))
atomic.StorePointer(&kItem.Transient, unsafe.Pointer(i))
return visitor(i)
}
if err := p.visit(keys, start, true, v); err != nil {
return err
}
return vErr
}
示例4: Copy
func (nloc *nodeLoc) Copy(src *nodeLoc) *nodeLoc {
if src == nil {
return nloc.Copy(empty_nodeLoc)
}
atomic.StorePointer(&nloc.loc, unsafe.Pointer(src.Loc()))
atomic.StorePointer(&nloc.node, unsafe.Pointer(src.Node()))
return nloc
}
示例5: Copy
func (i *itemLoc) Copy(src *itemLoc) {
if src == nil {
i.Copy(empty_itemLoc)
return
}
atomic.StorePointer(&i.loc, unsafe.Pointer(src.Loc()))
atomic.StorePointer(&i.item, unsafe.Pointer(src.Item()))
}
示例6: collsPauseSwap
func (p *partitionstore) collsPauseSwap(cb func() (keys, changes *gkvlite.Collection)) {
p.lock.Lock()
defer p.lock.Unlock()
k, c := cb()
// Update the changes first, so that readers see a key index that's older.
atomic.StorePointer(&p.changes, unsafe.Pointer(c))
atomic.StorePointer(&p.keys, unsafe.Pointer(k))
}
示例7: RLock
// RLock readlock resurs from thread
// uses double check
func (t *TControl) RLock(threadId uint16, resursId string) {
var wlock *string
for {
wlock = (*string)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&t.writer))))
if wlock == nil || *wlock != resursId {
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&t.readers[threadId])), unsafe.Pointer(&resursId))
wlock = (*string)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&t.writer))))
if wlock == nil || *wlock != resursId {
return
}
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&t.readers[threadId])), nil)
}
t.sleep()
}
}
示例8: TestAtomicPointer
func TestAtomicPointer() {
b1 := &B{
B1: 3,
B2: "33",
}
atomic.StorePointer(&bp, unsafe.Pointer(b1))
fmt.Println(*((*B)(bp))) // {3 33}
// atomic.StorePointer(&unsafe.Pointer(b), unsafe.Pointer(b1)) // yonka_test\test_json.go:1472: cannot take the address of unsafe.Pointer(b)
b := &B{1, "11"}
p := unsafe.Pointer(b)
atomic.StorePointer(&p, unsafe.Pointer(b1))
fmt.Println(*((*B)(p))) // {3 33}
fmt.Println(*b) // {1 11}
}
示例9: ParseConfig
func ParseConfig(cfg string) {
if cfg == "" {
log.Fatalln("config file not specified: use -c $filename")
}
if !file.IsExist(cfg) {
log.Fatalln("config file specified not found:", cfg)
}
ConfigFile = cfg
configContent, err := file.ToTrimString(cfg)
if err != nil {
log.Fatalln("read config file", cfg, "error:", err.Error())
}
var c GlobalConfig
err = json.Unmarshal([]byte(configContent), &c)
if err != nil {
log.Fatalln("parse config file", cfg, "error:", err.Error())
}
if c.Migrate.Enabled && len(c.Migrate.Cluster) == 0 {
c.Migrate.Enabled = false
}
// set config
atomic.StorePointer(&ptr, unsafe.Pointer(&c))
log.Println("g.ParseConfig ok, file", cfg)
}
示例10: ReadFirst
func ReadFirst(b []byte, v interface{}) (read bool, total int, err error) {
var t unsafe.Pointer
var r *[2]marshal.Reader
if t = readerCache; t != nil {
if atomic.CompareAndSwapPointer(&readerCache, t, nil) {
r = (*[2]marshal.Reader)(t)
*r = [2]marshal.Reader{{Body: b}, {}}
goto Got
}
}
r = &[2]marshal.Reader{{Body: b}, {}}
Got:
total = r[0].IntUint32()
if total > 0 {
sz := r[0].IntUint32()
if r[0].Err == nil {
r[1].Body = r[0].Slice(sz + 4)
err = ReadRawTuple(&r[1], v)
read = true
} else {
err = r[0].Err
}
}
atomic.StorePointer(&readerCache, unsafe.Pointer(r))
return
}
示例11: SetValue
func (m *SharedMap) SetValue(key KeyType, value ValType) {
m.writeLock.Lock()
defer m.writeLock.Unlock()
newCurrent := m.Copy()
(*newCurrent)[key] = value
atomic.StorePointer(&m.current, unsafe.Pointer(newCurrent))
}
示例12: write
func (nloc *nodeLoc) write(o *Store) error {
if nloc != nil && nloc.Loc().isEmpty() {
node := nloc.Node()
if node == nil {
return nil
}
offset := atomic.LoadInt64(&o.size)
length := ploc_length + ploc_length + ploc_length + 8 + 8
b := make([]byte, length)
pos := 0
pos = node.item.Loc().write(b, pos)
pos = node.left.Loc().write(b, pos)
pos = node.right.Loc().write(b, pos)
binary.BigEndian.PutUint64(b[pos:pos+8], node.numNodes)
pos += 8
binary.BigEndian.PutUint64(b[pos:pos+8], node.numBytes)
pos += 8
if pos != length {
return fmt.Errorf("nodeLoc.write() pos: %v didn't match length: %v",
pos, length)
}
if _, err := o.file.WriteAt(b, offset); err != nil {
return err
}
atomic.StoreInt64(&o.size, offset+int64(length))
atomic.StorePointer(&nloc.loc,
unsafe.Pointer(&ploc{Offset: offset, Length: uint32(length)}))
}
return nil
}
示例13: compactSwapFile
func (s *bucketstore) compactSwapFile(bsf *bucketstorefile, compactPath string) error {
idx, ver, err := parseStoreFileName(filepath.Base(bsf.path), STORE_FILE_SUFFIX)
if err != nil {
return err
}
nextName := makeStoreFileName(idx, ver+1, STORE_FILE_SUFFIX)
nextPath := path.Join(filepath.Dir(bsf.path), nextName)
if err = os.Rename(compactPath, nextPath); err != nil {
return err
}
nextFile, err := fileService.OpenFile(nextPath, os.O_RDWR|os.O_CREATE)
if err != nil {
return err
}
nextBSF := NewBucketStoreFile(nextPath, nextFile, bsf.stats)
nextStore, err := gkvlite.NewStore(nextBSF)
if err != nil {
// TODO: Rollback the previous *.orig rename.
return err
}
nextBSF.store = nextStore
atomic.StorePointer(&s.bsf, unsafe.Pointer(nextBSF))
bsf.apply(func() {
bsf.purge = true // Mark the old file as purgable.
})
return nil
}
示例14: newMem
// Create new memdb and froze the old one; need external synchronization.
func (d *DB) newMem() (m *memdb.DB, err error) {
s := d.s
num := s.allocFileNum()
w, err := newJournalWriter(s.getJournalFile(num))
if err != nil {
s.reuseFileNum(num)
return
}
old := d.journal
d.journal = w
if old != nil {
old.close()
d.fjournal = old
}
d.fseq = d.seq
m = memdb.New(s.cmp)
mem := &memSet{cur: m}
if old := d.getMem_NB(); old != nil {
mem.froze = old.cur
}
atomic.StorePointer(&d.mem, unsafe.Pointer(mem))
return
}
示例15: NewRange
// NewRange initializes the range using the given metadata.
func NewRange(desc *proto.RangeDescriptor, rm rangeManager) (*Range, error) {
r := &Range{
rm: rm,
cmdQ: NewCommandQueue(),
tsCache: NewTimestampCache(rm.Clock()),
respCache: NewResponseCache(desc.RaftID, rm.Engine()),
pendingCmds: map[cmdIDKey]*pendingCmd{},
}
r.setDescWithoutProcessUpdate(desc)
lastIndex, err := r.loadLastIndex()
if err != nil {
return nil, err
}
atomic.StoreUint64(&r.lastIndex, lastIndex)
appliedIndex, err := r.loadAppliedIndex(r.rm.Engine())
if err != nil {
return nil, err
}
atomic.StoreUint64(&r.appliedIndex, appliedIndex)
lease, err := loadLeaderLease(r.rm.Engine(), desc.RaftID)
if err != nil {
return nil, err
}
atomic.StorePointer(&r.lease, unsafe.Pointer(lease))
if r.stats, err = newRangeStats(desc.RaftID, rm.Engine()); err != nil {
return nil, err
}
return r, nil
}