private void Push(WaitItem item) { lock (mPool) { mPool.Push(item); } }
public EchoStatus TrySendReceive(byte[] message, bool retryOnNak, byte receiveMessageId, InsteonMessageType?receiveMessageType, out Dictionary <PropertyKey, int> properties) { properties = null; WaitItem item = new WaitItem(receiveMessageId, receiveMessageType); lock (waitList) waitList.Add(item); EchoStatus status = TrySend(message, retryOnNak); if (status == EchoStatus.ACK) { if (item.Message == null) { item.MessageEvent.WaitOne(Constants.sendReceiveTimeout); } if (item.Message != null) { properties = item.Message.Properties; } else { logger.ErrorFormat("Did not receive expected message reply; SentMessage='{0}', ExpectedReceiveMessageId={1:X2}, Timeout={2}ms", Utilities.ByteArrayToString(message), receiveMessageId, Constants.sendReceiveTimeout); } } lock (waitList) waitList.Remove(item); return(status); }
/// <summary> /// 等待指定命令回复 /// </summary> /// <param name="responseCommand">指定命令</param> /// <param name="timeout">最长等待时间</param> /// <returns></returns> public TPKGHead WaitTerminalResponse(string tid, uint?token, int timeout = 30000) { TerminalResponseWaitItemKey key = new TerminalResponseWaitItemKey() { TerminalId = tid, SessionId = token }; var item = new WaitItem <TerminalResponseWaitItemKey, TPKGHead>(key, timeout); cache.AddWaitItem(key, item); item.WaitOne(); cache.Remove(key); return(item.Result); }
public void Free(PspPointer DataPointer) { if (!UsedBlocks.Contains(DataPointer)) { throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK); } UsedBlocks.Remove(DataPointer); FreeBlocks.Add(DataPointer); foreach (var WaitItem in WaitItemList.ToArray()) { //Console.Error.WriteLine("Free!"); WaitItemList.Remove(WaitItem); WaitItem.WakeUp(); ThreadManForUser.ThreadManager.Current.CpuThreadState.Yield(); break; } }
private void UpdateWaitItems(InsteonMessage message) { lock (waitList) { for (int i = 0; i < waitList.Count; ++i) { WaitItem item = waitList[i]; if (message.MessageId == item.MessageId) { if (item.Message == null) { item.Message = message; item.MessageEvent.Set(); } } } } }
/// <summary> /// 线程执行完毕后的触发事件 /// </summary> /// <param name="task"></param> private void WorkComplete(Task task) { lock (_lock) { // 检查是否有等待执行的操作,如果有等待的优先执行等待的任务 if (_waitQueue.Count > 0) { WaitItem item = _waitQueue.Dequeue(); task.TaskWorkItem = item.Works; task.ContextData = item.Context; task.Active(); } else { _working.Remove(task.Key); // 如果没有等待执行的操作就回收多余的工作线程 if (_freeQueue.Count >= _min) { _allPool.Remove(task.Key); task.Close(); } else { // 如果没超过就把线程从工作字典放入空闲队列 task.ContextData = null; task.TaskWorkItem = null; _freeQueue.Enqueue(task); } } if (_working.Count == 0 && _waitQueue.Count == 0) { _completedEvent.Set(); } if (_waitQueue.Count < _max) { _freeEvent.Set(); } } }
public EchoStatus TrySendReceive(byte[] message, bool retryOnNak, byte receiveMessageId, out Dictionary<PropertyKey, int> properties) { properties = null; var item = new WaitItem(receiveMessageId); lock (this.waitList) this.waitList.Add(item); var status = this.TrySend(message, retryOnNak); if (status == EchoStatus.ACK) { if (item.Message == null) item.MessageEvent.WaitOne(Constants.sendReceiveTimeout); if (item.Message != null) properties = item.Message.Properties; else Log.WriteLine("ERROR: Did not receive expected message reply; SentMessage='{0}', ExpectedReceiveMessageId={1:X2}, Timeout={2}ms", Utilities.ByteArrayToString(message), receiveMessageId, Constants.sendReceiveTimeout); } lock (this.waitList) this.waitList.Remove(item); return status; }
public EchoStatus TrySendReceive(byte[] message, bool retryOnNak, byte receiveMessageId, InsteonMessageType? receiveMessageType, out Dictionary<PropertyKey, int> properties) { properties = null; WaitItem item = new WaitItem(receiveMessageId, receiveMessageType); lock (waitList) waitList.Add(item); EchoStatus status = TrySend(message, retryOnNak); if (status == EchoStatus.ACK) { if (item.Message == null) { item.MessageEvent.WaitOne(Constants.sendReceiveTimeout); } if (item.Message != null) { properties = item.Message.Properties; } else { logger.ErrorFormat("Did not receive expected message reply; SentMessage='{0}', ExpectedReceiveMessageId={1:X2}, Timeout={2}ms", Utilities.ByteArrayToString(message), receiveMessageId, Constants.sendReceiveTimeout); } } lock (waitList) waitList.Remove(item); return status; }
// In this dialogue, the user asks for information regarding some object, // using a question of the form "What is a <Q>", where <Q> is the query term. // The agent first checks if the information is available in its long-term memory. // If not, it runs an internet (Wikipedia) search to try to find an answer. private void GenerateWhatIsDialogue() { Boolean isAlwaysAvailable = true; double inputTimeoutInterval = double.MaxValue; // No reason to have a timeout here, since the dialogue is _activated_ upon receiving matching input. int inputMaximumRepetitionCount = int.MaxValue; // No reason to have a repetition count here, for the reason just mentioned. double searchWaitingTime = 5.0; Dialogue whatIsDialogue = new Dialogue("WhatIsDialogue", isAlwaysAvailable); // The user asks a question of the form "What is a <Q>"? InputItem itemWI1 = new InputItem("WI1", new List <string>() { AgentConstants.QUERY_TAG_1 }, inputTimeoutInterval, inputMaximumRepetitionCount, "", ""); InputAction inputActionWI1 = new InputAction(whatIsDialogue.Context, "WI2"); inputActionWI1.PatternList.Add(new Pattern("What is [a an]" + " " + AgentConstants.QUERY_TAG_1)); inputActionWI1.PatternList.Add(new Pattern("What is " + " " + AgentConstants.QUERY_TAG_1)); itemWI1.InputActionList.Add(inputActionWI1); whatIsDialogue.DialogueItemList.Add(itemWI1); // The agent searches its long-term memory for (the description of) an object (tag = object) with the required name MemorySearchItem itemWI2 = new MemorySearchItem("WI2", AgentConstants.LONG_TERM_MEMORY_NAME, new List <string>() { AgentConstants.QUERY_TAG_1 }, new List <string>() { "object" }, TagSearchMode.Or, "name", "description", AgentConstants.QUERY_TAG_3, whatIsDialogue.Context, "WI7", whatIsDialogue.Context, "WI3"); whatIsDialogue.DialogueItemList.Add(itemWI2); // If the information cannot be found in long-term memory OutputItem itemWI3 = new OutputItem("WI3", AgentConstants.SPEECH_OUTPUT_TAG, null, false, 1); itemWI3.OutputAction = new OutputAction(whatIsDialogue.Context, "WI4"); itemWI3.OutputAction.PatternList.Add(new Pattern("I don't know, but I will find out")); itemWI3.OutputAction.PatternList.Add(new Pattern("Just a moment, let me check")); whatIsDialogue.DialogueItemList.Add(itemWI3); // Run a search... OutputItem itemWI4 = new OutputItem("WI4", AgentConstants.INTERNET_OUTPUT_TAG, new List <string>() { AgentConstants.QUERY_TAG_1 }, false, 1); itemWI4.OutputAction = new OutputAction(whatIsDialogue.Context, "WI5"); itemWI4.OutputAction.PatternList.Add(new Pattern("Wiki|Object|" + " " + AgentConstants.QUERY_TAG_1)); whatIsDialogue.DialogueItemList.Add(itemWI4); // ...and await the results (and the search memory again) WaitItem itemWI5 = new WaitItem("WI5", searchWaitingTime); itemWI5.OutputAction = new OutputAction(whatIsDialogue.Context, "WI2"); whatIsDialogue.DialogueItemList.Add(itemWI5); // If the item IS found: OutputItem itemWI7 = new OutputItem("WI7", AgentConstants.SPEECH_OUTPUT_TAG, new List <string>() { AgentConstants.QUERY_TAG_3 }, false, 1); itemWI7.OutputAction = new OutputAction("", ""); itemWI7.OutputAction.PatternList.Add(new Pattern(AgentConstants.QUERY_TAG_3)); whatIsDialogue.DialogueItemList.Add(itemWI7); agent.DialogueList.Add(whatIsDialogue); }