Ejemplo n.º 1
0
        /// <inheritdoc />
        public async Task <IDisposable> AquireEntityLockAsync(NetworkEntityGuid guid)
        {
            //basically, root lock so nobody can change the entity state until we're done.
            //We lock read globally and then write for the entity

            IDisposable root  = null;
            IDisposable child = null;

            try
            {
                //TODO: It's POSSIBLE, but unlikely that the entity was removed. Or that they didn't check?
                root = await InternalGlobalLock.ReaderLockAsync().ConfigureAwait(false);

                if (!EntityRefCountingMap.ContainsKey(guid.RawGuidValue))
                {
                    throw new InvalidOperationException($"Entity: {guid} does not exist in the locking service.");
                }

                //TODO: Should we do a write lock?
                child = await EntityLockingObjectMap[guid.RawGuidValue].WriterLockAsync().ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                child?.Dispose();
                root?.Dispose();
            }

            //MUST dispose this to dispose the locks.
            return(new AggregateDisposableLock(root, child));
        }
Ejemplo n.º 2
0
 /// <inheritdoc />
 public async Task <bool> ContainsLockingServiceForAsync(NetworkEntityGuid guid)
 {
     using (await InternalGlobalLock.ReaderLockAsync().ConfigureAwait(false))
     {
         //We don't need to check value.
         return(EntityRefCountingMap.ContainsKey(guid.RawGuidValue));
     }
 }