示例#1
0
            public Locks(int concurrencyLevel)
            {
                m_locks           = new ReadWriteLock[concurrencyLevel];
                m_lockWriteCounts = new int[concurrencyLevel];

                for (int i = 0; i < m_locks.Length; i++)
                {
                    m_locks[i] = ReadWriteLock.Create();
                }
            }
示例#2
0
        /// <summary>
        /// Class constructor
        /// </summary>
        public MutableDirectedGraph()
        {
            m_edgeSetBuffer = new BigBuffer <LinkedEdgeSetItem>();
            m_edgeSet       = new ConcurrentBigSet <LinkedEdgeSetItem>(backingItemsBuffer: m_edgeSetBuffer);

            // Create enough locks to ensure reasonable low contention even
            // if all threads are accessing this data structure
            m_locks = new ReadWriteLock[Environment.ProcessorCount * 4];
            for (int i = 0; i < m_locks.Length; i++)
            {
                m_locks[i] = ReadWriteLock.Create();
            }
        }
示例#3
0
        /// <summary>
        /// Constructs a new lossy cache
        /// </summary>
        /// <param name="capacity">the capacity determining the number of slots available in the cache. For best results, this should be a prime number.</param>
        /// <param name="comparer">the equality comparer for computing hash codes and equality of keys</param>
        public ObjectCache(int capacity, IEqualityComparer <TKey> comparer = null)
        {
            Contract.Requires(capacity > 0);

            m_slots = new Entry[capacity];
            var locks = new ReadWriteLock[HashCodeHelper.GetGreaterOrEqualPrime(Math.Min(Environment.ProcessorCount * 4, capacity))];

            for (int i = 0; i < locks.Length; i++)
            {
                locks[i] = ReadWriteLock.Create();
            }

            m_locks    = locks;
            m_comparer = comparer ?? EqualityComparer <TKey> .Default;
        }