Contains information on the thread that has locked an object.
예제 #1
0
        bool IShielded.CanCommit(WriteStamp writeStamp)
        {
            var locals = _localDict.Value;

            locals.Locked = true;
            // locals were prepared when we enlisted.
            if (locals.Items.Any(kvp =>
            {
                ItemKeeper v;
                return(_writeStamps.ContainsKey(kvp.Key) ||
                       (_dict.TryGetValue(kvp.Key, out v) && v.Version > Shield.ReadStamp));
            }))
            {
                return(false);
            }
            else
            {
                // touch only the ones we plan to change
                if (locals.HasChanges)
                {
                    foreach (var kvp in locals.Items)
                    {
                        if (kvp.Value != null)
                        {
                            _writeStamps[kvp.Key] = writeStamp;
                        }
                    }
                }
                return(true);
            }
        }
예제 #2
0
 /// <summary>
 /// Performs the commit check on the enlisted items.
 /// </summary>
 public bool CanCommit(WriteStamp ws)
 {
     foreach (var item in this)
     {
         if (!item.CanCommit(ws))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #3
0
        bool IShielded.CanCommit(WriteStamp writeStamp)
        {
            var res = _writerStamp == null &&
                      _current.Version <= Shield.ReadStamp;

            if (res && _locals.HasValue)
            {
                _writerStamp = writeStamp;
            }
            return(res);
        }
예제 #4
0
        /// <summary>
        /// Called after a thread checked and can commit. This will assign it a
        /// unique stamp to use for writing. This method will enter the new stamp
        /// into the stamp.Version. It must be done here to guarantee that no
        /// GetReaderTicket will return your stamp number before it has been
        /// written into your stamp lock! After completing your write, place your
        /// changes into the ticket, and this class will trim the old versions at
        /// the correct time. It is critical that this be done, which is why this
        /// method returns it as an out param - to make sure no exception can
        /// cause us to lose the ref to the ticket, if it is already in the chain.
        /// </summary>
        public static void NewVersion(WriteStamp stamp, out WriteTicket ticket)
        {
            // this version is running under the _checkLock, guaranteed to be alone!
            var newNode = new VersionEntry();

            ticket = newNode;

            var newStamp = _current.Stamp + 1;

            newNode.SetStamp(newStamp);
            stamp.Version  = newStamp;
            _current.Later = newNode;
            _current       = newNode;
        }
예제 #5
0
        void IShielded.Rollback()
        {
            if (!_locals.HasValue)
            {
                return;
            }
            var ws = _writerStamp;

            if (ws != null && ws.Locker == Shield.Context)
            {
                _writerStamp = null;
            }
            _locals.Release();
        }
예제 #6
0
        void IShielded.Commit()
        {
            if (!_locals.HasValue)
            {
                return;
            }
            var newCurrent = _locals.Value;

            newCurrent.Older   = _current;
            newCurrent.Version = _writerStamp.Version.Value;
            _current           = newCurrent;
            _writerStamp       = null;
            _locals.Release();
        }
예제 #7
0
        /// <summary>
        /// Called after a thread checked and can commit. This will assign it a
        /// unique stamp to use for writing. This method will enter the new stamp
        /// into the stamp.Version. It must be done here to guarantee that no
        /// GetReaderTicket will return your stamp number before it has been
        /// written into your stamp lock! After completing your write, place your
        /// changes into the ticket, and this class will trim the old versions at
        /// the correct time. It is critical that this be done, which is why this
        /// method returns it as an out param - to make sure no exception can
        /// cause us to lose the ref to the ticket, if it is already in the chain.
        /// </summary>
        public static void NewVersion(WriteStamp stamp, out WriteTicket ticket)
        {
            // this version is running under the _checkLock, guaranteed to be alone!
            var newNode = new VersionEntry();
            ticket = newNode;

            var newStamp = _current.Stamp + 1;
            newNode.SetStamp(newStamp);
            stamp.Version = newStamp;
            _current.Later = newNode;
            _current = newNode;
        }
예제 #8
0
 bool IShielded.CanCommit(WriteStamp writeStamp)
 {
     return true;
 }
예제 #9
0
 bool IShielded.CanCommit(WriteStamp writeStamp)
 {
     return(true);
 }