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


Golang atomic.LoadUintptr函数代码示例

本文整理汇总了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
	}
}
开发者ID:rjammala,项目名称:emgo,代码行数:13,代码来源:ticks-cortexm.go

示例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
}
开发者ID:twmb,项目名称:dash,代码行数:17,代码来源:block.go

示例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
}
开发者ID:yireyun,项目名称:go-pool,代码行数:25,代码来源:pools.go

示例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
}
开发者ID:balamurugana,项目名称:mc,代码行数:18,代码来源:watcher_readdcw.go

示例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
}
开发者ID:suzukaze,项目名称:fluentd-forwarder,代码行数:35,代码来源:output.go

示例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
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:30,代码来源:exec_windows.go

示例7: initGoType

func initGoType(fold *valueFold) {
	if cdata.Ref() == atomic.LoadUintptr(&guiPaintRef) {
		go RunMain(func() { _initGoType(fold, true) })
	} else {
		_initGoType(fold, false)
	}
}
开发者ID:pmeido,项目名称:Arianrhod,代码行数:7,代码来源:bridge.go

示例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
}
开发者ID:shelmesky,项目名称:go1.5.1,代码行数:33,代码来源:pool.go

示例9: Peek

func (q *StreamQueue) Peek() []byte {
	tail := (*Node)(unsafe.Pointer(atomic.LoadUintptr(&q.tail)))

	tail.RLock()
	defer tail.RUnlock()

	return tail.data
}
开发者ID:better0332,项目名称:zhibo,代码行数:8,代码来源:streamQueue.go

示例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
}
开发者ID:pmeido,项目名称:Arianrhod,代码行数:60,代码来源:bridge.go

示例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
}
开发者ID:GeertJohan,项目名称:qml,代码行数:56,代码来源:bridge.go

示例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
}
开发者ID:Maplecms,项目名称:golang1.5-src,代码行数:15,代码来源:pool.go

示例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()
	}
}
开发者ID:rjammala,项目名称:emgo,代码行数:13,代码来源:ticks-cortexm.go

示例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()
}
开发者ID:yireyun,项目名称:go-pool,代码行数:15,代码来源:pools.go

示例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
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:14,代码来源:exec_windows.go


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