Exemplo n.º 1
0
            internal Enumerator(WeakKeyDictionary <TKey, TValue> dictionary)
            {
                Requires.NotNull(dictionary, nameof(dictionary));

                this.enumerator = dictionary.dictionary.GetEnumerator();
                this.current    = default(KeyValuePair <TKey, TValue>);
            }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a <see cref="JoinableTask"/> instance as one that is relevant to the async operation.
        /// </summary>
        /// <param name="joinChild">The <see cref="JoinableTask"/> to join as a child.</param>
        internal JoinRelease AddDependency(JoinableTask joinChild)
        {
            Requires.NotNull(joinChild, nameof(joinChild));
            if (this == joinChild)
            {
                // Joining oneself would be pointless.
                return(default(JoinRelease));
            }

            using (this.Factory.Context.NoMessagePumpSynchronizationContext.Apply())
            {
                List <AsyncManualResetEvent> eventsNeedNotify = null;
                lock (this.owner.Context.SyncContextLock)
                {
                    if (this.childOrJoinedJobs == null)
                    {
                        this.childOrJoinedJobs = new WeakKeyDictionary <JoinableTask, int>(capacity: 3);
                    }

                    int refCount;
                    this.childOrJoinedJobs.TryGetValue(joinChild, out refCount);
                    this.childOrJoinedJobs[joinChild] = ++refCount;
                    if (refCount == 1)
                    {
                        // This constitutes a significant change, so we should apply synchronous task tracking to the new child.
                        var tasksNeedNotify = this.AddDependingSynchronousTaskToChild(joinChild);
                        if (tasksNeedNotify.Count > 0)
                        {
                            eventsNeedNotify = new List <AsyncManualResetEvent>(tasksNeedNotify.Count);
                            foreach (var taskToNotify in tasksNeedNotify)
                            {
                                if (taskToNotify.SynchronousTask.pendingEventSource == null || taskToNotify.TaskHasPendingMessages == taskToNotify.SynchronousTask)
                                {
                                    taskToNotify.SynchronousTask.pendingEventSource = new WeakReference <JoinableTask>(taskToNotify.TaskHasPendingMessages);
                                }

                                taskToNotify.SynchronousTask.pendingEventCount += taskToNotify.NewPendingMessagesCount;

                                var notifyEvent = taskToNotify.SynchronousTask.queueNeedProcessEvent;
                                if (notifyEvent != null)
                                {
                                    eventsNeedNotify.Add(notifyEvent);
                                }
                            }
                        }
                    }
                }

                // We explicitly do this outside our lock.
                if (eventsNeedNotify != null)
                {
                    foreach (var queueEvent in eventsNeedNotify)
                    {
                        queueEvent.PulseAll();
                    }
                }

                return(new JoinRelease(this, joinChild));
            }
        }
Exemplo n.º 3
0
            internal KeyEnumerator(WeakKeyDictionary <TKey, TValue> dictionary)
            {
                Requires.NotNull(dictionary, nameof(dictionary));

                // Assign a value to Current to suppress CS8618. The Current property may have a null value at times,
                // but the value will never be exposed to external code provided the code only accesses Current after a
                // call to MoveNext returns true.
                this.Current = default !;
 internal KeyEnumerable(WeakKeyDictionary <TKey, TValue> dictionary)
 {
     Requires.NotNull(dictionary, nameof(dictionary));
     this.dictionary = dictionary;
 }
            internal KeyEnumerator(WeakKeyDictionary <TKey, TValue> dictionary)
            {
                Requires.NotNull(dictionary, nameof(dictionary));

                this.enumerator = dictionary.dictionary.GetEnumerator();
            }