Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="DataStreamerClientBuffer{TK,TV}"/>.
        /// </summary>
        public DataStreamerClientBuffer(
            DataStreamerClientEntry <TK, TV>[] entries,
            DataStreamerClientPerNodeBuffer <TK, TV> parent,
            DataStreamerClientBuffer <TK, TV> previous)
        {
            Debug.Assert(parent != null);

            _entries  = entries;
            _parent   = parent;
            _previous = previous;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets or adds per-node buffer for the specified socket.
        /// </summary>
        private DataStreamerClientPerNodeBuffer <TK, TV> GetOrAddPerNodeBuffer(ClientSocket socket)
        {
            DataStreamerClientPerNodeBuffer <TK, TV> res;

            if (_buffers.TryGetValue(socket, out res))
            {
                return(res);
            }

            var candidate = new DataStreamerClientPerNodeBuffer <TK, TV>(this, socket);

            res = _buffers.GetOrAdd(socket, candidate);

            if (res != candidate)
            {
                // Another thread won - return array to the pool.
                ReturnPooledArray(candidate.Close().Entries);
            }

            return(res);
        }