本文整理匯總了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)
}
}
}
示例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)
}
示例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))
}
}
示例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)})
}
示例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()
}
}
示例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
}
示例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
}
示例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
}
示例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]
}
示例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]
}
示例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指針
}
示例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]
}
示例13: StoreUintptr
func StoreUintptr(addr *uintptr, val uintptr) {
orig.StoreUintptr(addr, val)
}
示例14: EnableInvariantChecking
// Enable checking of invariants when locking and unlocking InvariantMutex.
func EnableInvariantChecking() {
atomic.StoreUintptr(&gEnable, 1)
}