本文整理匯總了Golang中sync/atomic.LoadUintptr函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoadUintptr函數的具體用法?Golang LoadUintptr怎麽用?Golang LoadUintptr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了LoadUintptr函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loadTicks
func loadTicks() uint64 {
aba := atomic.LoadUintptr(&ticksABA)
for {
barrier.Compiler()
t := ticks[aba&1]
barrier.Compiler()
aba1 := atomic.LoadUintptr(&ticksABA)
if aba == aba1 {
return t
}
aba = aba1
}
}
示例2: Prime
// Prime, called before a function that may fail, returns what you will call
// Wait with. If you do not call wait, and this call successfully primes the
// block, you must call Cancel.
func (b *Block) Prime(last uintptr) (primer uintptr, primed bool) {
primer = atomic.LoadUintptr(&b.counter)
if primer != last {
return
}
runtime.Gosched()
primer = atomic.LoadUintptr(&b.counter)
if primer != last || atomic.LoadUint32(&b.lock.write) != 0 {
return
}
primed = true
atomic.AddInt32(&b.waiters, 1)
return
}
示例3: getSlow
func (p *Pools) getSlow() (x interface{}) {
// See the comment in pin regarding ordering of the loads.
size := atomic.LoadUintptr(&p.localSize) // load-acquire
local := p.local // load-consume
// Try to steal one element from other procs.
pid := runtime_procPin()
runtime_procUnpin()
for i := 0; i < int(size); i++ {
l := indexLocals(local, (pid+i+1)%int(size))
l.Lock()
last := len(l.shared) - 1
if last >= 0 {
x = l.shared[last]
l.shared = l.shared[:last]
l.Unlock()
break
}
l.Unlock()
}
if x == nil && p.New != nil {
x = p.New()
}
return x
}
示例4: lazyinit
// lazyinit creates an I/O completion port and starts the main event processing
// loop. This method uses Double-Checked Locking optimization.
func (r *readdcw) lazyinit() (err error) {
invalid := uintptr(syscall.InvalidHandle)
if atomic.LoadUintptr((*uintptr)(&r.cph)) == invalid {
r.Lock()
defer r.Unlock()
if atomic.LoadUintptr((*uintptr)(&r.cph)) == invalid {
cph := syscall.InvalidHandle
if cph, err = syscall.CreateIoCompletionPort(cph, 0, 0, 0); err != nil {
return
}
r.cph, r.start = cph, true
go r.loop()
}
}
return
}
示例5: sendBuffer
func (output *ForwardOutput) sendBuffer(buf []byte) error {
for len(buf) > 0 {
if atomic.LoadUintptr(&output.isShuttingDown) != 0 {
break
}
err := output.ensureConnected()
if err != nil {
output.logger.Info("Will be retried in %s", output.retryInterval.String())
time.Sleep(output.retryInterval)
continue
}
startTime := time.Now()
if output.writeTimeout == 0 {
output.conn.SetWriteDeadline(time.Time{})
} else {
output.conn.SetWriteDeadline(startTime.Add(output.writeTimeout))
}
n, err := output.conn.Write(buf)
buf = buf[n:]
if err != nil {
output.logger.Error("Failed to flush buffer (reason: %s, left: %d bytes)", err.Error(), len(buf))
err_, ok := err.(net.Error)
if !ok || (!err_.Timeout() && !err_.Temporary()) {
output.conn.Close()
output.conn = nil
continue
}
}
if n > 0 {
elapsed := time.Now().Sub(startTime)
output.logger.Info("Forwarded %d bytes in %f seconds (%d bytes left)\n", n, elapsed.Seconds(), len(buf))
}
}
return nil
}
示例6: wait
func (p *Process) wait() (ps *ProcessState, err error) {
handle := atomic.LoadUintptr(&p.handle)
s, e := syscall.WaitForSingleObject(syscall.Handle(handle), syscall.INFINITE)
switch s {
case syscall.WAIT_OBJECT_0:
break
case syscall.WAIT_FAILED:
return nil, NewSyscallError("WaitForSingleObject", e)
default:
return nil, errors.New("os: unexpected result from WaitForSingleObject")
}
var ec uint32
e = syscall.GetExitCodeProcess(syscall.Handle(handle), &ec)
if e != nil {
return nil, NewSyscallError("GetExitCodeProcess", e)
}
var u syscall.Rusage
e = syscall.GetProcessTimes(syscall.Handle(handle), &u.CreationTime, &u.ExitTime, &u.KernelTime, &u.UserTime)
if e != nil {
return nil, NewSyscallError("GetProcessTimes", e)
}
p.setDone()
// NOTE(brainman): It seems that sometimes process is not dead
// when WaitForSingleObject returns. But we do not know any
// other way to wait for it. Sleeping for a while seems to do
// the trick sometimes. So we will sleep and smell the roses.
defer time.Sleep(5 * time.Millisecond)
defer p.Release()
return &ProcessState{p.Pid, syscall.WaitStatus{ExitCode: ec}, &u}, nil
}
示例7: initGoType
func initGoType(fold *valueFold) {
if cdata.Ref() == atomic.LoadUintptr(&guiPaintRef) {
go RunMain(func() { _initGoType(fold, true) })
} else {
_initGoType(fold, false)
}
}
示例8: getSlow
/*
嘗試從其他P的poolLocal的shared列表獲取
*/
func (p *Pool) getSlow() (x interface{}) {
// See the comment in pin regarding ordering of the loads.
size := atomic.LoadUintptr(&p.localSize) // load-acquire
local := p.local // load-consume
// Try to steal one element from other procs.
pid := runtime_procPin()
runtime_procUnpin()
for i := 0; i < int(size); i++ {
// 循環從其他P獲取poolLocal
l := indexLocal(local, (pid+i+1)%int(size))
l.Lock()
last := len(l.shared) - 1
// 如果某個P的poolLocal的shared列表不為空
// 則獲取shared列表的最後一個元素並跳出循環
if last >= 0 {
x = l.shared[last]
l.shared = l.shared[:last]
l.Unlock()
break
}
l.Unlock()
}
// 如果循環所有P的poolLocal都沒有找到
// 則創建一個新的
if x == nil && p.New != nil {
x = p.New()
}
return x
}
示例9: Peek
func (q *StreamQueue) Peek() []byte {
tail := (*Node)(unsafe.Pointer(atomic.LoadUintptr(&q.tail)))
tail.RLock()
defer tail.RUnlock()
return tail.data
}
示例10: wrapGoValue
// wrapGoValue creates a new GoValue object in C++ land wrapping
// the Go value contained in the given interface.
//
// This must be run from the main GUI thread.
func wrapGoValue(engine *Engine, gvalue interface{}, owner valueOwner) (cvalue unsafe.Pointer) {
gvaluev := reflect.ValueOf(gvalue)
gvaluek := gvaluev.Kind()
if gvaluek == reflect.Struct && !hashable(gvalue) {
name := gvaluev.Type().Name()
if name != "" {
name = " (" + name + ")"
}
panic("cannot hand an unhashable struct value" + name + " to QML logic; use its address instead")
}
if gvaluek == reflect.Ptr && gvaluev.Elem().Kind() == reflect.Ptr {
panic("cannot hand pointer of pointer to QML logic; use a simple pointer instead")
}
painting := cdata.Ref() == atomic.LoadUintptr(&guiPaintRef)
// Cannot reuse a jsOwner because the QML runtime may choose to destroy
// the value _after_ we hand it a new reference to the same value.
// See issue #68 for details.
prev, ok := engine.values[gvalue]
if ok && (prev.owner == cppOwner || painting) {
return prev.cvalue
}
if painting {
panic("cannot allocate new objects while painting")
}
parent := nilPtr
if owner == cppOwner {
parent = engine.addr
}
fold := &valueFold{
engine: engine,
gvalue: gvalue,
owner: owner,
}
fold.cvalue = C.newGoValue(unsafe.Pointer(fold), typeInfo(gvalue), parent)
if prev != nil {
// Put new fold first so the single cppOwner, if any, is always the first entry.
fold.next = prev
prev.prev = fold
}
engine.values[gvalue] = fold
//fmt.Printf("[DEBUG] value alive (wrapped): cvalue=%x gvalue=%x/%#v\n", fold.cvalue, addrOf(fold.gvalue), fold.gvalue)
stats.valuesAlive(+1)
C.engineSetContextForObject(engine.addr, fold.cvalue)
switch owner {
case cppOwner:
C.engineSetOwnershipCPP(engine.addr, fold.cvalue)
case jsOwner:
C.engineSetOwnershipJS(engine.addr, fold.cvalue)
}
return fold.cvalue
}
示例11: wrapGoValue
// wrapGoValue creates a new GoValue object in C++ land wrapping
// the Go value contained in the given interface.
//
// This must be run from the main GUI thread.
func wrapGoValue(engine *Engine, gvalue interface{}, owner valueOwner) (cvalue unsafe.Pointer) {
gvaluev := reflect.ValueOf(gvalue)
gvaluek := gvaluev.Kind()
if gvaluek == reflect.Struct && !hashable(gvalue) {
name := gvaluev.Type().Name()
if name != "" {
name = " (" + name + ")"
}
panic("cannot hand an unhashable struct value" + name + " to QML logic; use its address instead")
}
if gvaluek == reflect.Ptr && gvaluev.Elem().Kind() == reflect.Ptr {
panic("cannot hand pointer of pointer to QML logic; use a simple pointer instead")
}
painting := tref.Ref() == atomic.LoadUintptr(&guiPaintRef)
prev, ok := engine.values[gvalue]
if ok && (prev.owner == owner || owner != cppOwner || painting) {
return prev.cvalue
}
if painting {
panic("cannot allocate new objects while painting")
}
parent := nilPtr
if owner == cppOwner {
parent = engine.addr
}
fold := &valueFold{
engine: engine,
gvalue: gvalue,
owner: owner,
}
fold.cvalue = C.newGoValue(unsafe.Pointer(fold), typeInfo(gvalue), parent)
if prev != nil {
prev.next = fold
fold.prev = prev
} else {
engine.values[gvalue] = fold
}
//fmt.Printf("[DEBUG] value alive (wrapped): cvalue=%x gvalue=%x/%#v\n", fold.cvalue, addrOf(fold.gvalue), fold.gvalue)
stats.valuesAlive(+1)
C.engineSetContextForObject(engine.addr, fold.cvalue)
switch owner {
case cppOwner:
C.engineSetOwnershipCPP(engine.addr, fold.cvalue)
case jsOwner:
C.engineSetOwnershipJS(engine.addr, fold.cvalue)
}
return fold.cvalue
}
示例12: pin
// pin pins the current goroutine to P, disables preemption and returns poolLocal pool for the P.
// Caller must call runtime_procUnpin() when done with the pool.
func (p *Pool) pin() *poolLocal { // 獲取特定於P的pool
pid := runtime_procPin() // 獲得當前P的id
// In pinSlow we store to localSize and then to local, here we load in opposite order.
// Since we've disabled preemption, GC can not happen in between.
// Thus here we must observe local at least as large localSize.
// We can observe a newer/larger local, it is fine (we must observe its zero-initialized-ness).
s := atomic.LoadUintptr(&p.localSize) // load-acquire 獲得pool的本地大小
l := p.local // load-consume
if uintptr(pid) < s { // 如果pid小於localSize的大小,表明P的數量無變化,直接取出poolLocal
return indexLocal(l, pid) // 返回對應pid的poolLocal
}
return p.pinSlow() // 如果獲得的pid大於localSize,表明P的大小變化了,使用pinSlow獲得poolLocal
}
示例13: 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()
}
}
示例14: pin
// pin pins the current goroutine to P, disables preemption and returns poolsLocal pool for the P.
// Caller must call runtime_procUnpin() when done with the pool.
func (p *Pools) pin() *poolsLocal {
pid := runtime_procPin()
// In pinSlow we store to localSize and then to local, here we load in opposite order.
// Since we've disabled preemption, GC can not happen in between.
// Thus here we must observe local at least as large localSize.
// We can observe a newer/larger local, it is fine (we must observe its zero-initialized-ness).
s := atomic.LoadUintptr(&p.localSize) // load-acquire
l := p.local // load-consume
if uintptr(pid) < s {
return indexLocals(l, pid)
}
return p.pinSlow()
}
示例15: 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
}