Example #1
0
        /// <summary>
        /// Prevents further modification to graph and indicates that the graph
        /// should switch to being read-optimized
        /// </summary>
        public void Seal()
        {
            using (m_globalLock.AcquireWriteLock())
            {
                m_state = MutableGraphState.Sealed;

                // Remove the edge set which is only needed for deduplication when adding
                m_edgeSet = null;
            }
        }
Example #2
0
        /// <summary>
        /// Takes a read or write lock for the given operation depending on the state of the graph .
        /// For instance, there can be concurrent edge additions while in the Mutating state for the same node/lock,
        /// but enumeration will take an exclusive lock to ensure it gets consistent information while graph is in Mutating state.
        /// Once the graph enters the sealed state, enumerations allow sharing. Therefore, operations that enumerate edges will pass
        /// sharingState = Sealed while the AddEdge operation passes sharingState = Mutating.
        /// </summary>
        /// <param name="rwLock">the read write lock to acquire read or write access from</param>
        /// <param name="sharingState">specifies the state for which concurrent access is allowed for the operation protected by this lock</param>
        /// <returns>the read or write lock (as a switch read write lock)</returns>
        private SwitchReadWriteLock AcquireLockForState(ReadWriteLock rwLock, MutableGraphState sharingState)
        {
            if (!rwLock.IsValid)
            {
                return(default(SwitchReadWriteLock));
            }

            using (m_globalLock.HasExclusiveAccess ? ReadLock.Invalid : m_globalLock.AcquireReadLock())
            {
                return(new SwitchReadWriteLock(rwLock, isSharing: sharingState == m_state));
            }
        }