public Task<Token> AcquireAsync()
        {
            OwnerToken nextOwner = new OwnerToken();
            Task<Token> task = nextOwner.Task;
            lock (this.nextOwners)
            {
                if (this.owner == null)
                {
                    this.owner = nextOwner;
                    nextOwner.Complete();
                }
                else
                {
                    this.nextOwners.Enqueue(nextOwner);
                }
            }

            return task;
        }
Exemple #2
0
        public Task <Token> AcquireAsync()
        {
            OwnerToken   nextOwner = new OwnerToken();
            Task <Token> task      = nextOwner.Task;

            lock (this.nextOwners)
            {
                if (this.owner == null)
                {
                    this.owner = nextOwner;
                    nextOwner.Complete();
                }
                else
                {
                    this.nextOwners.Enqueue(nextOwner);
                }
            }

            return(task);
        }
Exemple #3
0
        public void Release(Token token)
        {
            OwnerToken nextOwner = null;

            lock (this.nextOwners)
            {
                if (this.owner != token)
                {
                    throw new InvalidOperationException("The token is not valid.");
                }

                this.owner = null;
                if (this.nextOwners.Count > 0)
                {
                    nextOwner  = this.nextOwners.Dequeue();
                    this.owner = nextOwner;
                }
            }

            if (nextOwner != null)
            {
                nextOwner.Complete();
            }
        }