private MalockTaskTable RemoveTable(MalockTaskType type) { lock (this.tables) { MalockTaskTable table; this.tables.TryRemove(type, out table); return(table); } }
private void Handle(MalockTaskType type, MalockTaskTable tables) { foreach (var kv in tables) { LinkedList <MalockTaskInfo> tasks = kv.Value; MalockTaskInfo info = null; LinkedListNode <MalockTaskInfo> node = null; lock (tasks) { node = tasks.First; if (node == null) { continue; } info = node.Value; } bool success = false; Stopwatch sw = info.Stopwatch; if (sw != null && info.Timeout != -1 && sw.ElapsedMilliseconds > info.Timeout) { success = this.engine.Timeout(info); } else { switch (type) { case MalockTaskType.kEnter: success = this.engine.Enter(info); break; case MalockTaskType.kExit: success = this.engine.Exit(info); break; case MalockTaskType.kAbort: success = this.engine.Abort(info); break; case MalockTaskType.kGetAllInfo: success = this.engine.GetAllInfo(info); break; } } if (success) { lock (tasks) { if (node.List != null) { tasks.Remove(node); } } } } }
private MalockTaskTable GetTable(MalockTaskType type) { lock (this.tables) { ConcurrentDictionary <string, LinkedList <MalockTaskInfo> > table; if (!this.tables.TryGetValue(type, out table)) { table = new ConcurrentDictionary <string, LinkedList <MalockTaskInfo> >(); this.tables.TryAdd(type, table); } return(table); } }