当前位置: 首页>>代码示例>>Golang>>正文


Golang atomic.StoreInt32函数代码示例

本文整理汇总了Golang中sync/atomic.StoreInt32函数的典型用法代码示例。如果您正苦于以下问题:Golang StoreInt32函数的具体用法?Golang StoreInt32怎么用?Golang StoreInt32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了StoreInt32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SetEmitDiagnosticNotices

// SetEmitDiagnosticNotices toggles whether diagnostic notices
// are emitted. Diagnostic notices contain potentially sensitive
// circumvention network information; only enable this in environments
// where notices are handled securely (for example, don't include these
// notices in log files which users could post to public forums).
func SetEmitDiagnosticNotices(enable bool) {
	if enable {
		atomic.StoreInt32(&noticeLogDiagnostics, 1)
	} else {
		atomic.StoreInt32(&noticeLogDiagnostics, 0)
	}
}
开发者ID:adamkruger,项目名称:psiphon-tunnel-core,代码行数:12,代码来源:notice.go

示例2: ResetElectionTimeoutMs

// ResetElectionTimeoutMs sets the minimum and maximum election timeouts to the
// passed values, and returns the old values.
func ResetElectionTimeoutMs(newMin, newMax int) (int, int) {
	oldMin := atomic.LoadInt32(&minimumElectionTimeoutMs)
	oldMax := atomic.LoadInt32(&maximumElectionTimeoutMs)
	atomic.StoreInt32(&minimumElectionTimeoutMs, int32(newMin))
	atomic.StoreInt32(&maximumElectionTimeoutMs, int32(newMax))
	return int(oldMin), int(oldMax)
}
开发者ID:bernerdschaefer,项目名称:raft,代码行数:9,代码来源:server.go

示例3: SetDisabled

// SetDisabled turns replica scanning off or on as directed. Note that while
// disabled, removals are still processed.
func (rs *replicaScanner) SetDisabled(disabled bool) {
	if disabled {
		atomic.StoreInt32(&rs.disabled, 1)
	} else {
		atomic.StoreInt32(&rs.disabled, 0)
	}
}
开发者ID:YuleiXiao,项目名称:cockroach,代码行数:9,代码来源:helpers_test.go

示例4: setunreliable

// please do not change these two functions.
func (px *Paxos) setunreliable(what bool) {
	if what {
		atomic.StoreInt32(&px.unreliable, 1)
	} else {
		atomic.StoreInt32(&px.unreliable, 0)
	}
}
开发者ID:EdisonCodeKeeper,项目名称:course-6.824-distributed-systems,代码行数:8,代码来源:paxos.go

示例5: setHasChecked

func (c *checkerT) setHasChecked(b bool) {
	if b {
		atomic.StoreInt32(&c.check, 1)
	} else {
		atomic.StoreInt32(&c.check, 0)
	}
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:7,代码来源:available_unix.go

示例6: AwaitTimeout

//
// AwaitOrFail, the count must be <= 0 before the duration expires.
// Will Return true on timeout or cancel.
//
func (c *CountdownLatch) AwaitTimeout(duration time.Duration) bool {

	c.awaitMutex.Lock()
	defer func() {
		atomic.StoreInt32(&c.completed, 1)
		c.awaitMutex.Unlock()
	}()

	if c.Completed() {
		panic(LatchError{LatchCompleted: true})
	}

	to := time.After(duration)

	for {
		select {

		case <-to:
			atomic.StoreInt32(&c.timedOut, 1)
			return true

		case <-c.cancel:
			atomic.StoreInt32(&c.canceled, 1)
			return true

		case <-c.zeroReached:
			atomic.StoreInt32(&c.completed, 1)
			return false
			break
		}
	}
}
开发者ID:R358,项目名称:brace,代码行数:36,代码来源:cntdwn.go

示例7: recheckTxs

// NOTE: pass in goodTxs because mem.txs can mutate concurrently.
func (mem *Mempool) recheckTxs(goodTxs []types.Tx) {
	if len(goodTxs) == 0 {
		return
	}
	atomic.StoreInt32(&mem.rechecking, 1)
	mem.recheckCursor = mem.txs.Front()
	mem.recheckEnd = mem.txs.Back()

	for _, tx := range goodTxs {
		err := sm.ExecTx(mem.cache, tx, false, nil)
		if err != nil {
			// Tx became invalidated due to newly committed block.
			mem.txs.Remove(mem.recheckCursor)
			mem.recheckCursor.DetachPrev()
		}
		if mem.recheckCursor == mem.recheckEnd {
			mem.recheckCursor = nil
		} else {
			mem.recheckCursor = mem.recheckCursor.Next()
		}
		if mem.recheckCursor == nil {
			// Done!
			atomic.StoreInt32(&mem.rechecking, 0)
		}
	}
}
开发者ID:ZhuZhengyi,项目名称:eris-db,代码行数:27,代码来源:mempool.go

示例8: Write

func (b *AtomicBool) Write(value bool) {
	if value {
		atomic.StoreInt32(&(b.val), 1)
	} else {
		atomic.StoreInt32(&(b.val), 0)
	}
}
开发者ID:simulatedsimian,项目名称:tracetcp-go,代码行数:7,代码来源:utils.go

示例9: test9400

func test9400(t *testing.T) {
	// We synchronize through a shared variable, so we need two procs
	defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2))

	// Start signaller
	atomic.StoreInt32(&issue9400.Baton, 0)
	go func() {
		// Wait for RewindAndSetgid
		for atomic.LoadInt32(&issue9400.Baton) == 0 {
			runtime.Gosched()
		}
		// Broadcast SIGSETXID
		runtime.LockOSThread()
		C.setgid(0)
		// Indicate that signalling is done
		atomic.StoreInt32(&issue9400.Baton, 0)
	}()

	// Grow the stack and put down a test pattern
	const pattern = 0x123456789abcdef
	var big [1024]uint64 // len must match assmebly
	for i := range big {
		big[i] = pattern
	}

	// Temporarily rewind the stack and trigger SIGSETXID
	issue9400.RewindAndSetgid()

	// Check test pattern
	for i := range big {
		if big[i] != pattern {
			t.Fatalf("entry %d of test pattern is wrong; %#x != %#x", i, big[i], uint64(pattern))
		}
	}
}
开发者ID:danny8002,项目名称:go,代码行数:35,代码来源:issue9400_linux.go

示例10: SetDebug

// SetDebug turns on/off debugging mode, that causes Fatalf to panic
func SetDebug(enabled bool) {
	if enabled {
		atomic.StoreInt32(&debug, 1)
	} else {
		atomic.StoreInt32(&debug, 0)
	}
}
开发者ID:gravitational,项目名称:trace,代码行数:8,代码来源:trace.go

示例11: setunreliable

// please do not change these two functions.
func (sm *ShardMaster) setunreliable(what bool) {
	if what {
		atomic.StoreInt32(&sm.unreliable, 1)
	} else {
		atomic.StoreInt32(&sm.unreliable, 0)
	}
}
开发者ID:gitter-badger,项目名称:haze-kv,代码行数:8,代码来源:server.go

示例12: RecursiveRewatch

// RecrusiveRewatch implements RecursiveWatcher interface. It fails:
//
//   * with errNotWatched when the given path is not being watched
//   * with errInvalidEventSet when oldevent does not match the current event set
//   * with errAlreadyWatched when watch-point given by the oldpath was meant to
//     be relocated to newpath, but the newpath is already watched
//   * a non-nil error when setting the watch-point with FSEvents fails
//
// TODO(rjeczalik): Improve handling of watch-point relocation? See two TODOs
// that follows.
func (fse *fsevents) RecursiveRewatch(oldpath, newpath string, oldevent, newevent Event) error {
	switch [2]bool{oldpath == newpath, oldevent == newevent} {
	case [2]bool{true, true}:
		w, ok := fse.watches[oldpath]
		if !ok {
			return errNotWatched
		}
		atomic.StoreInt32(&w.isrec, 1)
		return nil
	case [2]bool{true, false}:
		w, ok := fse.watches[oldpath]
		if !ok {
			return errNotWatched
		}
		if !atomic.CompareAndSwapUint32(&w.events, uint32(oldevent), uint32(newevent)) {
			return errors.New("invalid event state diff")
		}
		atomic.StoreInt32(&w.isrec, 1)
		return nil
	default:
		// TODO(rjeczalik): rewatch newpath only if exists?
		// TODO(rjeczalik): migrate w.prev to new watch?
		if _, ok := fse.watches[newpath]; ok {
			return errAlreadyWatched
		}
		if err := fse.Unwatch(oldpath); err != nil {
			return err
		}
		// TODO(rjeczalik): revert unwatch if watch fails?
		return fse.watch(newpath, newevent, 1)
	}
}
开发者ID:balamurugana,项目名称:mc,代码行数:42,代码来源:watcher_fsevents.go

示例13: TestPauseMetadata

func TestPauseMetadata(t *testing.T) {
	opts := NewOptions()
	opts.Logger = newTestLogger(t)
	_, _, nsqd := mustStartNSQD(opts)
	defer os.RemoveAll(opts.DataPath)
	defer nsqd.Exit()

	// avoid concurrency issue of async PersistMetadata() calls
	atomic.StoreInt32(&nsqd.isLoading, 1)
	topicName := "pause_metadata" + strconv.Itoa(int(time.Now().Unix()))
	topic := nsqd.GetTopic(topicName)
	channel := topic.GetChannel("ch")
	atomic.StoreInt32(&nsqd.isLoading, 0)
	nsqd.PersistMetadata()

	b, _ := metadataForChannel(nsqd, 0, 0).Get("paused").Bool()
	equal(t, b, false)

	channel.Pause()
	b, _ = metadataForChannel(nsqd, 0, 0).Get("paused").Bool()
	equal(t, b, false)

	nsqd.PersistMetadata()
	b, _ = metadataForChannel(nsqd, 0, 0).Get("paused").Bool()
	equal(t, b, true)

	channel.UnPause()
	b, _ = metadataForChannel(nsqd, 0, 0).Get("paused").Bool()
	equal(t, b, true)

	nsqd.PersistMetadata()
	b, _ = metadataForChannel(nsqd, 0, 0).Get("paused").Bool()
	equal(t, b, false)
}
开发者ID:APTrust,项目名称:exchange,代码行数:34,代码来源:nsqd_test.go

示例14: setValid

func (c *monitorServCli) setValid(valid bool) {
	if valid {
		atomic.StoreInt32(&c.valid, validMark)
	} else {
		atomic.StoreInt32(&c.valid, invalidMark)
	}
}
开发者ID:RivenZoo,项目名称:goutil,代码行数:7,代码来源:monitor.go

示例15: NewOutboundPeer

func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {

	p := &Peer{
		outputQueue: make(chan *ethwire.Msg, outputBufferSize),
		quit:        make(chan bool),
		ethereum:    ethereum,
		inbound:     false,
		connected:   0,
		disconnect:  0,
		caps:        caps,
		Version:     fmt.Sprintf("/Ethereum(G) v%s/%s", ethutil.Config.Ver, runtime.GOOS),
	}

	// Set up the connection in another goroutine so we don't block the main thread
	go func() {
		conn, err := net.DialTimeout("tcp", addr, 30*time.Second)

		if err != nil {
			ethutil.Config.Log.Debugln("Connection to peer failed", err)
			p.Stop()
			return
		}
		p.conn = conn

		// Atomically set the connection state
		atomic.StoreInt32(&p.connected, 1)
		atomic.StoreInt32(&p.disconnect, 0)

		p.Start()
	}()

	return p
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:33,代码来源:peer.go


注:本文中的sync/atomic.StoreInt32函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。