public static bool AwaitCompletion(IEnumerable <Task> initialTasks) { Dispatch(initialTasks); while (Interlocked.CompareExchange(ref activeTasks, 0, 0) > 0) { if (!Application.ProcessLogMessages()) { Thread.Sleep(TimerTickInterval); } Task task; while (pendingTasks.Dequeue(out task)) { if (!task.IsPending) { if (!dispatcher.Dispatch(instance, task)) { throw new EntryPointNotFoundException(); } } else if (!pendingTasks.Enqueue(task)) { throw new IndexOutOfRangeException(); } } } return(Interlocked.CompareExchange(ref errors, 0, 0) == 0); }
public static void SetupClient() { Client.Start(SERVER_IP, 1025, 1026, "MainRover"); DrivePackets = new QueueBuffer(); StopPackets = new QueueBuffer(); ModePackets = new QueueBuffer(); PathPackets = new QueueBuffer(); Parse.SetParseHandler(0x80, (Packet) => StopPackets.Enqueue(Packet, 0)); Parse.SetParseHandler(0x99, (Packet) => ModePackets.Enqueue(Packet, 0)); for (byte i = 0x8E; i <= 0x94; i++) { Parse.SetParseHandler(i, (Packet) => DrivePackets.Enqueue(Packet, 0)); } Parse.SetParseHandler(0x98, (Packet) => DrivePackets.Enqueue(Packet, 0)); for (byte i = 0x9A; i <= 0xA1; i++) { Parse.SetParseHandler(i, (Packet) => DrivePackets.Enqueue(Packet, 0)); } for (byte i = 0x95; i <= 0x97; i++) { Parse.SetParseHandler(i, (Packet) => PathPackets.Enqueue(Packet, 0)); } PathSpeed = 0; PathAngle = 0; }
/// <summary> /// 取出队头,并放在队尾 /// 若已取空,从DB中移入 /// because user buffer class does not have this operation, lstWaitingIDInDB is treated as long type here /// on 2011-5-22, it is modified that only lstWaitingID.Count>0, MaxLengthInMem items are removed from DB into memory, so that the performance is enhanced /// </summary> public long RollQueue() { //从数据库队列缓存中移入元素 while (lstWaitingID.Count == 0) { lstWaitingID = lstWaitingIDInDB.GetFirstValues(iMaxLengthInMem); } if (lstWaitingID.Count == 0) { return(0); } //记录队头 long lFirstValue = lstWaitingID.First.Value; lock (oLock) { //移入队尾,并从队头移除 if (lstWaitingID.Count < iMaxLengthInMem && lstWaitingIDInDB.Count == 0) { lstWaitingID.AddLast(lFirstValue); } else { lstWaitingIDInDB.Enqueue(lFirstValue); } lstWaitingID.RemoveFirst(); //从数据库队列缓存中移入元素 while (lstWaitingID.Count == 0) { lstWaitingID = lstWaitingIDInDB.GetFirstValues(iMaxLengthInMem); } } return(lFirstValue); }
void Run() { while (run) { try { var m = SubMission.Dequeue(); if (m == null) { subFree = true; are.WaitOne(1); } else { subFree = false; try { m.action(m.data); } catch (Exception ex) { #if DEBUG Debug.LogError(ex.StackTrace); #endif } if (m.waitAction != null) //如果有等待的任务 { if (m.Id == MainID) //交给主线程 { m.action = m.waitAction; m.waitAction = null; MainMission.Enqueue(m); goto label; } for (int i = 0; i < threads.Count; i++) { if (m.Id == threads[i].Id) { threads[i].AddMainMission(m.waitAction, m.data);//任务交给源线程 goto label; } } m.action = m.waitAction; m.waitAction = null; MainMission.Enqueue(m);//否则交给主线程 } label :; } } catch (Exception ex) { #if DEBUG Debug.LogError(ex.StackTrace); #endif } } are.Dispose(); }
public void TestLeakyBucketOrder() { QueueBuffer controller = new QueueBuffer(); controller.Enqueue(NewPacket(1, 0)); controller.Enqueue(NewPacket(2, 0)); controller.Enqueue(NewPacket(3, 0)); AssertPacket(controller.Dequeue(), 1, 0); AssertPacket(controller.Dequeue(), 2, 0); AssertPacket(controller.Dequeue(), 3, 0); Assert.AreEqual(controller.Dequeue(), null); }
static partial void LogInternal(string message, params object[] args) { if (Scope.LocalId == mainScopeId) { logSystem.Log(message, args); } else { while (!logBuffer.Enqueue(new KeyValuePair <byte, string>(2, string.Format(message, args)))) { ; } } }
public void AddMission(Action <object> action, object obj) { Mission mis = new Mission(); mis.action = action; mis.data = obj; queue.Enqueue(mis); }
public override void Dispatch(byte[] dat, byte tag) { KcpData data = new KcpData(); data.dat = dat; data.tag = tag; datas.Enqueue(data); }
public void AddSubMission(Action <object> action, object dat, Action <object> wait = null) { Mission mission = new Mission(); mission.action = action; mission.data = dat; mission.waitAction = wait; mission.Id = Thread.CurrentThread.ManagedThreadId; SubMission.Enqueue(mission); }
protected void RecycleItem() { int len = swap.Length; for (int i = 0; i < len; i++) { var it = swap.Pop(); it.target.SetActive(false); queue.Enqueue(it); } swap.Done(); }
public void TestLeakyBucketEmpty() { QueueBuffer controller = new QueueBuffer(); Assert.AreEqual(controller.Peek(), null); Assert.AreEqual(controller.Dequeue(), null); controller.Enqueue(NewPacket(10, 0)); AssertPacket(controller.Peek(), 10, 0); AssertPacket(controller.Dequeue(), 10, 0); Assert.AreEqual(controller.Peek(), null); Assert.AreEqual(controller.Dequeue(), null); }
public void TestLeakyBucketCapacity() { QueueBuffer controller = new QueueBuffer(); int capacity = 200000; for (int i = 0; i < capacity; i++) { controller.Enqueue(NewPacket(10, 0)); } controller.Peek(); for (int i = 0; i < capacity; i++) { controller.Dequeue(); } }
public override void Dispatch(BlockInfo dat, byte tag) { KcpData data = new KcpData(); data.tag = tag; unsafe { byte[] buf = new byte[dat.DataCount]; byte * src = dat.Addr; for (int i = 0; i < buf.Length; i++) { buf[i] = src[i]; } data.dat = buf; } datas.Enqueue(data); }
void EnvelopeCallback(byte[] data, byte tag) { if (auto) { if (MainDispatch != null) { MainDispatch(data, tag, endPoint); } } else { SocData soc = new SocData(); soc.data = data; soc.tag = tag; soc.obj = endPoint; queue.Enqueue(soc); } }
void SubBatch(object obj) { var m = Sub.Dequeue(); if (m != null) { PipeLine = m.PipeLine; scripts = m.scripts; vertex = m.vertex; uv = m.uv; uv1 = m.uv1; uv2 = m.uv2; uv3 = m.uv3; colors = m.colors; Batch(); Main.Enqueue(m); } }
public static void RecycleElement(ModelElement model) { if (model == null) { return; } RecycleQueue.Enqueue(model); if (model.baseEvent != null) { model.baseEvent.Dispose(); } var child = model.child; for (int i = 0; i < child.Count; i++) { RecycleElement(child[i]); } child.Clear(); }
protected void OrganizeSubVolume(List <EnvelopePart> list, int fs) { if (list != null) { for (int j = 0; j < list.Count; j++) { var item = list[j]; int ap = item.head.AllPart; if (ap > 1) { for (int i = 0; i < 128; i++) { if (item.head.MsgID == pool[i].head.MsgID) { if (pool[i].buff == null) { goto label; } if (Envelope.SetChecked(pool[i].checks, item.head.CurPart)) { Envelope.CopyToBuff(pool[i].buff, item.data, 0, item.head, fs); pool[i].part++; pool[i].rcvLen += item.head.PartLen; if (pool[i].rcvLen >= item.head.Lenth) { EnvelopeData data = new EnvelopeData(); data.data = pool[i].buff; data.type = (byte)(pool[i].head.Type); pool[i].buff = null; //pool[i].checks = null; QueueBuf.Enqueue(data); pool[i].done = true; } } goto label; } } int s = point; for (int i = 0; i < 128; i++) { if (pool[s].head.MsgID == 0 | pool[s].done) { point = s; break; } s++; if (s >= 128) { s = 0; } } pool[s].head = item.head; pool[s].part = 1; pool[s].rcvLen = item.head.PartLen; pool[s].buff = new byte[item.head.Lenth]; pool[s].time = DateTime.Now.Ticks; Envelope.CopyToBuff(pool[s].buff, item.data, 0, item.head, fs); int c = ap / 32 + 1; pool[s].checks = new Int32[c]; Envelope.SetChecked(pool[s].checks, item.head.CurPart); } else { EnvelopeData data = new EnvelopeData(); data.data = item.data; data.type = (byte)(item.head.Type); QueueBuf.Enqueue(data); } label :; } } }
public void TestLeakyBucketPriority() { QueueBuffer controller = new QueueBuffer(); controller.Enqueue(NewPacket(1, 0), 1); }