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); } }
/// <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); }
bool IShielded.CanCommit(WriteStamp writeStamp) { var res = _writerStamp == null && _current.Version <= Shield.ReadStamp; if (res && _locals.HasValue) { _writerStamp = writeStamp; } return(res); }
/// <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; }
void IShielded.Rollback() { if (!_locals.HasValue) { return; } var ws = _writerStamp; if (ws != null && ws.Locker == Shield.Context) { _writerStamp = null; } _locals.Release(); }
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(); }
bool IShielded.CanCommit(WriteStamp writeStamp) { return true; }
bool IShielded.CanCommit(WriteStamp writeStamp) { return(true); }