Esempio n. 1
0
        public async Task LockAsync()
        {
            await LockSemaphore.WaitAsync().ConfigureAwait(false);

            TimeoutCancelSource = new CancellationTokenSource();
            UnlockTask          = Task.Delay(TimeSpan.FromSeconds(30), TimeoutCancel);
            _ = UnlockTask.ContinueWith(InternalUnlock, TaskContinuationOptions.NotOnCanceled);
        }
Esempio n. 2
0
 /// <summary>
 /// Erzeugt eine neue Instanz einer ChunkColumn.
 /// </summary>
 public ChunkColumn(IPlanet planet)
 {
     Heights           = new int[Chunk.CHUNKSIZE_X, Chunk.CHUNKSIZE_Y];
     entities          = new EntityList(this);
     entitieSemaphore  = new LockSemaphore(1, 1);
     DefinitionManager = TypeContainer.Get <IDefinitionManager>();
     Planet            = planet;
     globalChunkCache  = planet.GlobalChunkCache;
 }
Esempio n. 3
0
 public DatabaseProvider(string rootPath, ILogger logger)
 {
     this.rootPath            = rootPath;
     this.logger              = (logger ?? NullLogger.Default).As(nameof(DatabaseProvider));
     planetSemaphore          = new LockSemaphore(1, 1);
     universeSemaphore        = new LockSemaphore(1, 1);
     globalSemaphore          = new LockSemaphore(1, 1);
     planetDatabaseRegister   = new Dictionary <(Type Type, Guid Universe, int PlanetId), Database.Database>();
     universeDatabaseRegister = new Dictionary <(Type Type, Guid Universe), Database.Database>();
     globalDatabaseRegister   = new Dictionary <Type, Database.Database>();
 }
Esempio n. 4
0
        /// <summary>
        /// Instanziert einen neuen local Chunk Cache.
        /// </summary>
        /// <param name="globalCache">Referenz auf global Chunk Cache</param>
        /// <param name="dimensions">Größe des Caches in Zweierpotenzen</param>
        /// <param name="range">Gibt die Range in alle Richtungen an.</param>
        public LocalChunkCache(IGlobalChunkCache globalCache, int dimensions, int range)
        {
            if (1 << dimensions < (range * 2) + 1)
                throw new ArgumentException("Range too big");

            
            semaphore = new LockSemaphore(1, 1);
            taskSemaphore = new LockSemaphore(1, 1);
            Planet = globalCache.Planet;
            this.globalCache = globalCache;
            this.range = range;

            limit = dimensions;
            mask = (1 << limit) - 1;
            chunkColumns = new IChunkColumn[(mask + 1) * (mask + 1)];
            logger = (TypeContainer.GetOrNull<ILogger>() ?? NullLogger.Default).As(typeof(LocalChunkCache));
        }
Esempio n. 5
0
        /// <summary>
        /// 指定したキーで待機します。
        /// </summary>
        /// <param name="key">待機するキー</param>
        public static async Task WaitAsync(string key)
        {
            await LockSemaphore.WaitAsync();

            try
            {
                if (!Semaphores.ContainsKey(key))
                {
                    Semaphores.Add(key, new SemaphoreSlim(1, 1));
                }
            }
            finally
            {
                LockSemaphore.Release();
            }
            await Semaphores[key].WaitAsync();
        }
Esempio n. 6
0
 public Pool()
 {
     internalStack     = new Stack <T>();
     semaphoreExtended = new LockSemaphore(1, 1);
 }
Esempio n. 7
0
 public ObserverHashSet(IEnumerable <INotificationObserver> collection, IEqualityComparer <INotificationObserver> comparer)
     : base(collection, comparer)
 {
     semaphore = new LockSemaphore(1, 1);
 }
Esempio n. 8
0
 public ObserverHashSet(IEnumerable <INotificationObserver> collection) : base(collection)
 {
     semaphore = new LockSemaphore(1, 1);
 }
Esempio n. 9
0
 public ObserverHashSet() : base()
 {
     semaphore = new LockSemaphore(1, 1);
 }
Esempio n. 10
0
 public QuoteProvider(FileInfo fileInfo)
 {
     this.fileInfo     = fileInfo;
     random            = new Random();
     semaphoreExtended = new LockSemaphore(1, 1);
 }
Esempio n. 11
0
 private void InternalUnlock(Task t)
 => LockSemaphore.Release();
Esempio n. 12
0
 public Task WaitAsync()
 => LockSemaphore.WaitAsync();
Esempio n. 13
0
 public Awaiter()
 {
     manualReset = new ManualResetEventSlim(false);
     semaphore   = new LockSemaphore(1, 1);
 }