示例#1
0
        public Task PulseAllAsync()
        {
            TaskCompletionSourceWithoutInlining <EmptyStruct> tcs = null;

            lock (this.syncObject)
            {
                // Atomically replace the completion source with a new, uncompleted source
                // while capturing the previous one so we can complete it.
                // This ensures that we don't leave a gap in time where WaitAsync() will
                // continue to return completed Tasks due to a Pulse method which should
                // execute instantaneously.
                tcs = this.taskCompletionSource;
                this.taskCompletionSource = this.CreateTaskSource();
                this.isSet = false;
            }

            tcs.TrySetResultToDefault();
            return(tcs.Task);
        }
示例#2
0
        public Task SetAsync()
        {
            TaskCompletionSourceWithoutInlining <EmptyStruct> tcs = null;
            bool transitionRequired = false;

            lock (this.syncObject)
            {
                transitionRequired = !this.isSet;
                tcs        = this.taskCompletionSource;
                this.isSet = true;
            }

            if (transitionRequired)
            {
                tcs.TrySetResultToDefault();
            }

            return(tcs.Task);
        }