示例#1
0
        /// <summary>
        /// 加锁  只有成功后,才会有 返回值
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static async Task Lock(this LockComponent self)
        {
            ++self.lockCount;                     //加锁次数++

            if (self.status == LockStatus.Locked) //如果已经锁定 跳出
            {
                return;
            }
            if (self.status == LockStatus.LockRequesting)              //如过当前是待加锁状态
            {
                await self.WaitLock();

                return;
            }

            self.status = LockStatus.LockRequesting;              //待加锁状态

            // 真身直接本地请求锁,镜像需要调用Rpc获取锁
            MasterComponent masterComponent = self.Entity.GetComponent <MasterComponent>();

            if (masterComponent != null)
            {
                await masterComponent.Lock(self.address);
            }
            else
            {
                self.RequestLock();
                await self.WaitLock();
            }
        }
示例#2
0
        public static async ETTask Lock(this LockComponent self)
        {
            ++self.lockCount;

            if (self.status == LockStatus.Locked)
            {
                return;
            }
            if (self.status == LockStatus.LockRequesting)
            {
                await self.WaitLock();

                return;
            }

            self.status = LockStatus.LockRequesting;

            // 真身直接本地请求锁,镜像需要调用Rpc获取锁
            MasterComponent masterComponent = self.Entity.GetComponent <MasterComponent>();

            if (masterComponent != null)
            {
                await masterComponent.Lock(self.address);
            }
            else
            {
                self.RequestLock().NoAwait();
                await self.WaitLock();
            }
        }