public async Task LockAsync() { await LockSemaphore.WaitAsync().ConfigureAwait(false); TimeoutCancelSource = new CancellationTokenSource(); UnlockTask = Task.Delay(TimeSpan.FromSeconds(30), TimeoutCancel); _ = UnlockTask.ContinueWith(InternalUnlock, TaskContinuationOptions.NotOnCanceled); }
/// <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; }
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>(); }
/// <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)); }
/// <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(); }
public Pool() { internalStack = new Stack <T>(); semaphoreExtended = new LockSemaphore(1, 1); }
public ObserverHashSet(IEnumerable <INotificationObserver> collection, IEqualityComparer <INotificationObserver> comparer) : base(collection, comparer) { semaphore = new LockSemaphore(1, 1); }
public ObserverHashSet(IEnumerable <INotificationObserver> collection) : base(collection) { semaphore = new LockSemaphore(1, 1); }
public ObserverHashSet() : base() { semaphore = new LockSemaphore(1, 1); }
public QuoteProvider(FileInfo fileInfo) { this.fileInfo = fileInfo; random = new Random(); semaphoreExtended = new LockSemaphore(1, 1); }
private void InternalUnlock(Task t) => LockSemaphore.Release();
public Task WaitAsync() => LockSemaphore.WaitAsync();
public Awaiter() { manualReset = new ManualResetEventSlim(false); semaphore = new LockSemaphore(1, 1); }