コード例 #1
0
        /// <summary>
        /// Compare this event's priority to the other group's priority. Finds and returns the highest priority event.
        /// </summary>
        /// <param name="previousHighest"></param>
        /// <param name="otherGroup">MUST HAVE THE LOCK ON THIS GROUP'S MUTEX</param>
        /// <returns></returns>
        private LockableLock chooseHighestPriority(LockableLock previousHighest, LockableLockGroup otherGroup)
        {
            LockableLock otherHighest = otherGroup.highestPriority();
            int          priority     = previousHighest.comparePriority(otherHighest);

            if (priority == 0)
            {
                if (otherGroup.subSubPriority == -1)
                {
                    otherGroup.subSubPriority = Interlocked.Increment(ref LockableLockGroup.PriorityChooser);
                }
                if (previousHighest.group.subSubPriority == -1)
                {
                    //Previous event doesn't have a priority yet and will get a new value later, which must be higher than otherGroup's value.
                    //So the other event has priority.
                    priority = -1;
                }
                else
                {
                    priority = otherHighest.group.subSubPriority - previousHighest.group.subSubPriority;
                }
            }
            if (priority < 0)
            {
                return(otherHighest);
            }
            return(previousHighest);
        }
コード例 #2
0
        /// <summary>
        /// Get the highest priority lock in this lock group.
        /// </summary>
        /// <returns></returns>
        private LockableLock highestPriority()
        {
            LockableLock highestPriority = this.eventQueue[0];

            for (int i = 0; i < eventQueue.Count; i++)
            {
                LockableLock otherEvent = eventQueue[i];
                if (highestPriority.comparePriority(otherEvent) < 0)
                {
                    highestPriority = otherEvent;
                }
            }
            return(highestPriority);
        }