public void Start() { if (running.CompareExchange(true, false)) { return; } Init(); }
private bool InternalExitByKey(string key, string identity, out object state, bool ignoreIdentity) { lock (this.syncobj) { state = null; SyncBlockIndex info; if (!syncblocks.TryGetValue(key, out info)) { return(false); } lock (info) { ISet <string> keys = string.IsNullOrEmpty(identity) ? null : GetAllKeyByIdentity(identity); try { if (keys != null) { Monitor.Enter(keys); } AtomicBoolean locker = info.Lock; if (!ignoreIdentity && info.Identity != identity) { return(false); } else { if (keys != null) { keys.Remove(key); } state = info.State; info.Identity = null; } locker.CompareExchange(true, false); } finally { if (keys != null) { Monitor.Exit(keys); } } } } return(true); }
public void Start() { if (running.CompareExchange(true, false)) { return; } Stopwatch watch = new Stopwatch(); watch.Start(); long lastFrameTime = 0L; // For deltaTime long drift = 0L; // Accounting for short-term spikes while (running) { lastFrameTime = Update(watch, lastFrameTime, ref drift); } watch.Stop(); }
public virtual bool Enter(string key, string enterIdentity, object state, out string exitIdentity) { if (enterIdentity == null) { throw new ArgumentNullException("enterIdentity"); } if (key == null) { throw new ArgumentNullException("key"); } if (key.Length <= 0) { throw new ArgumentOutOfRangeException("key"); } lock (this.syncobj) { exitIdentity = null; if (!this.AllocEnterKey(key)) { return(false); } SyncBlockIndex info; if (!syncblocks.TryGetValue(key, out info)) { return(false); } AtomicBoolean locker = null; lock (info) { locker = info.Lock; } bool localTaken = locker.CompareExchange(false, true); if (localTaken) { ISet <string> keys = GetAllKeyByIdentity(enterIdentity); do { bool addKeyToKeys = false; if (keys == null) { addKeyToKeys = false; } else { lock (keys) { addKeyToKeys = keys.Add(key); } } if (!addKeyToKeys) { localTaken = false; locker.CompareExchange(true, false); } else { lock (info) { exitIdentity = info.Identity; info.Identity = enterIdentity; info.State = state; } } } while (false); } return(localTaken); } }