Esempio n. 1
0
        public void Add(TKey key, TValue value)
        {
            SyncVersionList <TValue> list;
            bool found = this.data.TryGetValue(key, out list);

            if (!found)
            {
                list = SyncVersionList <TValue> .Create(new ValueVersion <TValue>(this.version + 1, value));
            }
            else
            {
                list.Add(new ValueVersion <TValue>(this.version + 1, value));
            }


            if (!found)
            {
                // TODO need to make SyncVersionList class for this to be atomic.
                this.data[key] = list;
            }

            // version is incremented after so that readers who start while `Add` has not finished
            // don't observe new value.
            // disallow reordering of next statement ? volatile `version`.
            this.version += 1;
        }
Esempio n. 2
0
            static public SyncVersionList <T> Create(ValueVersion <T> value)
            {
                var ret = new SyncVersionList <T>();

                ret.Initliaze(value);
                return(ret);
            }