/// <summary> /// Constructor of Semaphore class /// </summary> /// <param name="context">Specify a context to have different contexts in different domains</param> /// <param name="name">Name of the new Semaphore</param> /// <param name="initialCount">The initial number of requests for the semaphore that can be granted concurrently.</param> /// <param name="maximumCount">The maximum number of requests for the semaphore that can be granted concurrently.</param> public Semaphore(Context.Semaphore context, string name, int initialCount, int maximumCount) : base(context) { ContextMapper = ctx => ctx ?? _defaultContext; if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out var tempSemaphore)) { lock (ContextMapper.Invoke(context).LockerObject) { if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out tempSemaphore)) { _currentObject = new System.Threading.Semaphore(initialCount, maximumCount, name); ContextMapper.Invoke(context).ObjectDictionary.TryAdd(name, _currentObject); } } } if (tempSemaphore != null) { _currentObject = (System.Threading.Semaphore)tempSemaphore; } }
/// <summary> /// Specifies the context boundary for the new Semaphore /// </summary> /// <param name="value">An instance of Semaphore context</param> /// <returns></returns> public SemaphoreBuilder Context(Context.Semaphore value) { this._context = value; return(this); }