當前位置: 首頁>>代碼示例>>Golang>>正文


Golang atomic.StoreUintptr函數代碼示例

本文整理匯總了Golang中sync/atomic.StoreUintptr函數的典型用法代碼示例。如果您正苦於以下問題:Golang StoreUintptr函數的具體用法?Golang StoreUintptr怎麽用?Golang StoreUintptr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了StoreUintptr函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: regenPowChallenges

func regenPowChallenges() {
	c := time.Tick(100 * time.Millisecond)
	var deltaT float64
	for _ = range c {
		barrier := unixTime >> powRegenIntervalBits
		if curPowCollection.barrier < barrier {
			logMessage("Activating ProofOfWork challenges (barrier: %d)", barrier)
			atomic.StoreUintptr(
				(*uintptr)(unsafe.Pointer(&prevPowCollection)),
				(uintptr)(unsafe.Pointer(curPowCollection)),
			)
			atomic.StoreUintptr(
				(*uintptr)(unsafe.Pointer(&curPowCollection)),
				(uintptr)(unsafe.Pointer(nextPowCollection)),
			)

			timeToNextRun := float64(((barrier + 1) << powRegenIntervalBits) - unixTime)
			if (deltaT * 1.05) > timeToNextRun {
				logMessage(`WARNING: Last run (%.2fs) we were out of sync. `+
					`Sleeping remainder of cycle (%.2fs), hoping to get back in sync`,
					deltaT, timeToNextRun*1.05)
				time.Sleep(time.Duration(timeToNextRun*1.05) * time.Second)
				continue
			}
		}

		if nextPowCollection.barrier <= barrier {
			deltaT = updateNextPowCollection(barrier)
		}
	}
}
開發者ID:Freeaqingme,項目名稱:Webjobber,代碼行數:31,代碼來源:proofofwork.go

示例2: hookGoValuePaint

//export hookGoValuePaint
func hookGoValuePaint(enginep, foldp unsafe.Pointer, reflectIndex C.intptr_t) {
	fold := ensureEngine(enginep, foldp)
	v := reflect.ValueOf(fold.gvalue)

	// The main GUI thread is mutex-locked while paint methods are called,
	// so no two paintings should be happening at the same time.
	atomic.StoreUintptr(&guiPaintRef, tref.Ref())

	painter := &Painter{fold.engine, &Common{fold.cvalue, fold.engine}}

	method := v.Method(int(reflectIndex))
	method.Call([]reflect.Value{reflect.ValueOf(painter)})

	atomic.StoreUintptr(&guiPaintRef, 0)
}
開發者ID:GeertJohan,項目名稱:qml,代碼行數:16,代碼來源:bridge.go

示例3: BenchmarkAtomicUintPtr

func BenchmarkAtomicUintPtr(b *testing.B) {
	b.StopTimer()
	pointers := make([]uintptr, 1000)
	b.Log(unsafe.Sizeof(pointers[0]))
	b.StartTimer()

	for j := 0; j < b.N; j++ {
		atomic.StoreUintptr(&pointers[j%1000], uintptr(j))
	}
}
開發者ID:jannop64,項目名稱:tendermint,代碼行數:10,代碼來源:atomic_test.go

示例4: hookGoValuePaint

//export hookGoValuePaint
func hookGoValuePaint(enginep, foldp unsafe.Pointer, reflectIndex C.intptr_t) {
	// Besides a convenience this is a workaround for http://golang.org/issue/8588
	defer printPaintPanic()
	defer atomic.StoreUintptr(&guiPaintRef, 0)

	// The main GUI thread is mutex-locked while paint methods are called,
	// so no two paintings should be happening at the same time.
	atomic.StoreUintptr(&guiPaintRef, cdata.Ref())

	fold := ensureEngine(enginep, foldp)
	if fold.init.IsValid() {
		return
	}

	painter := &Painter{engine: fold.engine, obj: &Common{fold.cvalue, fold.engine, newConnections()}}
	v := reflect.ValueOf(fold.gvalue)
	method := v.Method(int(reflectIndex))
	method.Call([]reflect.Value{reflect.ValueOf(painter)})
}
開發者ID:pmeido,項目名稱:Arianrhod,代碼行數:20,代碼來源:bridge.go

示例5: sysTickHandler

func sysTickHandler() {
	aba := atomic.LoadUintptr(&ticksABA)
	t := ticks[aba&1]
	aba++
	ticks[aba&1] = t + 1
	barrier.Memory()
	atomic.StoreUintptr(&ticksABA, aba)
	tickEvent.Send()

	if tasker.onSysTick {
		exce.PendSV.SetPending()
	}
}
開發者ID:rjammala,項目名稱:emgo,代碼行數:13,代碼來源:ticks-cortexm.go

示例6: Push

func (q *StreamQueue) Push(data []byte) {
	tail := (*Node)(unsafe.Pointer(q.tail))
	tail.data = data
	defer tail.Unlock()

	if data != nil {
		n := &Node{}
		n.Lock()

		atomic.StoreUintptr(&q.tail, uintptr(unsafe.Pointer(n)))
	}
	return
}
開發者ID:better0332,項目名稱:zhibo,代碼行數:13,代碼來源:streamQueue.go

示例7: release

func (p *Process) release() error {
	handle := atomic.LoadUintptr(&p.handle)
	if handle == uintptr(syscall.InvalidHandle) {
		return syscall.EINVAL
	}
	e := syscall.CloseHandle(syscall.Handle(handle))
	if e != nil {
		return NewSyscallError("CloseHandle", e)
	}
	atomic.StoreUintptr(&p.handle, uintptr(syscall.InvalidHandle))
	// no need for a finalizer anymore
	runtime.SetFinalizer(p, nil)
	return nil
}
開發者ID:RajibTheKing,項目名稱:gcc,代碼行數:14,代碼來源:exec_windows.go

示例8: updateNextPowCollection

func updateNextPowCollection(barrier uint64) (deltaT float64) {
	t := time.Now()
	atomic.StoreUintptr(
		(*uintptr)(unsafe.Pointer(&nextPowCollection)),
		(uintptr)(unsafe.Pointer(newPowCollection(barrier+1))),
	)
	deltaT = time.Now().Sub(t).Seconds()
	logMessage("Created next set of ProofOfWork challenges in %.2fs", deltaT)
	intervalSeconds := math.Pow(2, float64(powRegenIntervalBits))
	if deltaT >= intervalSeconds {
		logMessage(
			"WARNING: Generating new Proof of Work challenges took longer (%.2fs) than the set interval (%.2fs)",
			deltaT,
			intervalSeconds)
	}

	return
}
開發者ID:Freeaqingme,項目名稱:Webjobber,代碼行數:18,代碼來源:proofofwork.go

示例9: pinSlow

func (p *Pool) pinSlow() *poolLocal {
	// Retry under the mutex.
	runtime_procUnpin()
	p.mu.Lock()
	defer p.mu.Unlock()
	pid := runtime_procPin()
	s := p.localSize
	l := p.local
	if uintptr(pid) < s {
		return indexLocal(l, pid)
	}
	if p.local == nil {
		p.globalOffset = unsafe.Offsetof(p.global)
		runtime_registerPool(p)
	}
	// If GOMAXPROCS changes between GCs, we re-allocate the array and lose the old one.
	size := runtime.GOMAXPROCS(0)
	local := make([]poolLocal, size)
	atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&p.local)), unsafe.Pointer(&local[0])) // store-release
	atomic.StoreUintptr(&p.localSize, uintptr(size))                                            // store-release
	return &local[pid]
}
開發者ID:TomHoenderdos,項目名稱:go-sunos,代碼行數:22,代碼來源:pool.go

示例10: pinSlow

func (p *Pools) pinSlow() *poolsLocal {
	// Retry under the mutex.
	// Can not lock the mutex while pinned.
	runtime_procUnpin()
	allPoolxsMu.Lock()
	defer allPoolxsMu.Unlock()
	pid := runtime_procPin()
	// poolsCleanup won't be called while we are pinned.
	s := p.localSize
	l := p.local
	if uintptr(pid) < s {
		return indexLocals(l, pid)
	}
	if p.local == nil {
		allPoolxs = append(allPoolxs, p)
	}
	// If GOMAXPROCS changes between GCs, we re-allocate the array and lose the old one.
	size := runtime.GOMAXPROCS(0)
	local := make([]poolsLocal, size)
	atomic.StorePointer((*unsafe.Pointer)(&p.local), unsafe.Pointer(&local[0])) // store-release
	atomic.StoreUintptr(&p.localSize, uintptr(size))                            // store-release
	return &local[pid]
}
開發者ID:yireyun,項目名稱:go-pool,代碼行數:23,代碼來源:pools.go

示例11: pinSlow

func (p *Pool) pinSlow() *poolLocal {
	// Retry under the mutex.
	// Can not lock the mutex while pinned.
	runtime_procUnpin() // 在allPoolsMu加鎖的情況下查找,這時候必須unpin
	allPoolsMu.Lock()
	defer allPoolsMu.Unlock() // 在allPoolsMu的保護下執行
	pid := runtime_procPin()  // 再次獲得P的id
	// poolCleanup won't be called while we are pinned.
	s := p.localSize
	l := p.local
	if uintptr(pid) < s { // 嘗試獲取poolLocal
		return indexLocal(l, pid)
	}
	if p.local == nil { // 獲取失敗,表明是第一次,將當前的Pool加入到allPools中
		allPools = append(allPools, p)
	}
	// If GOMAXPROCS changes between GCs, we re-allocate the array and lose the old one.
	size := runtime.GOMAXPROCS(0)                                               // 如果到這裏,表明P的數量發生變化了,丟棄以前的poolLocal
	local := make([]poolLocal, size)                                            // 分配procs個poolLocal
	atomic.StorePointer((*unsafe.Pointer)(&p.local), unsafe.Pointer(&local[0])) // store-release 存儲poolLocal
	atomic.StoreUintptr(&p.localSize, uintptr(size))                            // store-release 存儲大小
	return &local[pid]                                                          // 返回對應P的poolLocal指針
}
開發者ID:Maplecms,項目名稱:golang1.5-src,代碼行數:23,代碼來源:pool.go

示例12: pinSlow

func (p *Pool) pinSlow() *poolLocal {
	// Retry under the mutex.
	// Can not lock the mutex while pinned.
	runtime_procUnpin()
	allPoolsMu.Lock()
	defer allPoolsMu.Unlock()
	// 將當前goroutine綁定到P並禁止搶占,返回P的ID
	// 這樣做是防止goroutine被掛起之後再次運行時P已經發生變化
	pid := runtime_procPin()
	// poolCleanup won't be called while we are pinned.
	// p.localsize是Pool的大小
	// p.local是池中的每個元素
	s := p.localSize
	l := p.local
	// 如果pid<s,說明池中有元素
	// 如果>s,說明s為0,也就是說池的大小為0
	// 在池中根據P的id索引一個poolLocal
	if uintptr(pid) < s {
		return indexLocal(l, pid)
	}
	// 如果p.local為nil(池為空)
	// 將當前Pool加入到allPools
	if p.local == nil {
		allPools = append(allPools, p)
	}
	// If GOMAXPROCS changes between GCs, we re-allocate the array and lose the old one.
	// 獲取當前P的數量
	size := runtime.GOMAXPROCS(0)
	// 根據P的數量生成poolLocal池
	local := make([]poolLocal, size)
	// 將poolLocal池和吃的大小保存到Pool變量
	atomic.StorePointer((*unsafe.Pointer)(&p.local), unsafe.Pointer(&local[0])) // store-release
	atomic.StoreUintptr(&p.localSize, uintptr(size))                            // store-release
	// 最後根據P的id返回池中的元素
	return &local[pid]
}
開發者ID:shelmesky,項目名稱:go1.5.1,代碼行數:36,代碼來源:pool.go

示例13: StoreUintptr

func StoreUintptr(addr *uintptr, val uintptr) {
	orig.StoreUintptr(addr, val)
}
開發者ID:nimishzynga,項目名稱:go-couchbase,代碼行數:3,代碼來源:sync_386.go

示例14: EnableInvariantChecking

// Enable checking of invariants when locking and unlocking InvariantMutex.
func EnableInvariantChecking() {
	atomic.StoreUintptr(&gEnable, 1)
}
開發者ID:horzadome,項目名稱:gcsfuse,代碼行數:4,代碼來源:invariant_mutex.go


注:本文中的sync/atomic.StoreUintptr函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。