[手游项目3]-10-Go语言atomic原子操作

https://studygolang.com/articles/3557

func (self *Observe) Frame(frameIdx int, frames map[int]*PVPFrame) {
	if self == nil || self.roomid <= 0 {
		return
	}
	if !self.IsRunning() {
		return
	}
	if !self.HasWatcher() {
		return
	}
	recvmax := atomic.LoadInt32(&self.lastrecv)
	if int32(frameIdx) <= recvmax {
		return
	}

	for idx := recvmax + 1; idx <= int32(frameIdx); idx++ {
		frame, ok := frames[int(idx)]
		if !ok {
			continue
		}
		self.frames.Store(idx, frame)
	}
	atomic.StoreInt32(&self.lastrecv, int32(frameIdx))
}

猜你喜欢

转载自blog.csdn.net/q277055799/article/details/88799081