/// <summary> ///Clear 的测试 ///</summary> public void ClearTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 target.Clear(); Assert.Inconclusive("无法验证不返回值的方法。"); }
private static void ExecutePending(SafeQueue <Action> queue, UniqueId id) { var didEnter = false; try { didEnter = ReentryGuardHelper.Enter(id); if (!didEnter) { // called from inside this method - skip return; } while (queue.TryTake(out var action)) { action.Invoke(); } } finally { if (didEnter) { ReentryGuardHelper.Leave(id); } } }
//----------------------------------// /// <summary> /// Initialize a new action sequence. /// </summary> public ActionSequence(Needle needle = null) { _pair = new ActionPair(); _pair.ActionB = new ActionSet(Next); _queue = new SafeQueue <IAction>(); _needle = needle ?? ManagerUpdate.Control; }
public Progressor(IObservable <T> wrapped) { var buffer = new SafeQueue <T>(); wrapped.Subscribe ( new CustomObserver <T> ( () => _done = true, exception => _done = true, buffer.Add ) ); _proxy = new ProxyObservable <T>(); _tryTake = (out T value) => { if (buffer.TryTake(out value)) { _proxy.OnNext(value); return(true); } value = default(T); return(false); }; }
//-------------------------------------------// public TaskMachine(IAction <string> onEachTask = null) { _tasks = new SafeQueue <Act>(); _onDone = new ActionEvent(); _ticker = new Ticker(_onDone, 0); _onEachTask = onEachTask; _lock = new Lock(); }
/// <summary> /// Constructor. /// </summary> /// <param name="configuration">Configuration</param> public ThreadMonitorManager(Configuration configuration) : base() { this.Configuration = configuration; this.MonitorFactories = new SafeList<IThreadMonitorFactory>(); this.ThreadExecutionMonitors = new SafeList<ThreadExecutionMonitorMultiplexer>(); this.DestroyedExecutionMonitorIds = new SafeQueue<int>(); }
public RetryEngine() { this.disposed = false; this.taskQueue = new SafeQueue <TaskBag <TTask> >(); this.retryList = new SafeList <TaskBag <TTask> >(); this.eventSafeTrigger = new EventSafeTrigger(); this.retryingCount = 0; }
/// <summary> /// Constructor. /// </summary> /// <param name="configuration">Configuration</param> public ThreadMonitorManager(Configuration configuration) : base() { this.Configuration = configuration; this.MonitorFactories = new SafeList <IThreadMonitorFactory>(); this.ThreadExecutionMonitors = new SafeList <ThreadExecutionMonitorMultiplexer>(); this.DestroyedExecutionMonitorIds = new SafeQueue <int>(); }
// //编写测试时,还可使用以下属性: // //使用 ClassInitialize 在运行类中的第一个测试前先运行代码 //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //使用 ClassCleanup 在运行完类中的所有测试后再运行代码 //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //使用 TestInitialize 在运行每个测试前先运行代码 //[TestInitialize()] //public void MyTestInitialize() //{ //} // //使用 TestCleanup 在运行完每个测试后运行代码 //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///Count 的测试 ///</summary> public void CountTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 int actual; actual = target.Count; Assert.Inconclusive("验证此测试方法的正确性。"); }
protected virtual void Dispose(bool disposing) { // This is a protected method, the parameter should be kept _disposed = true; _event.Dispose(); _asyncWaiters = null; _event = null; }
/// <summary> ///Enqueue 的测试 ///</summary> public void EnqueueTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 ValueT value = default(ValueT); // TODO: 初始化为适当的值 target.Enqueue(value); Assert.Inconclusive("无法验证不返回值的方法。"); }
public ConcurrentQueue(IEnumerable <T> collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } _wrapped = new SafeQueue <T>(collection); }
/// <summary> /// Thread processing the audio queue /// </summary> protected virtual void doWork() { if (udp != null) { udp.Connect(ip); ip.Port = udpPort; ip.Address = udpIPAddress; logger.Info(string.Format("UDP connected to: {0}:{1}", ip.Address, ip.Port)); } samplesQ = new SafeQueue <byte[]>((uint)Thread.CurrentThread.ManagedThreadId); // q ident logger.Debug(string.Format("Starting wavOut {0}, entering endless loop", threadName)); play(); //virtual while (true) { eWaitHandle handle = (eWaitHandle)WaitHandle.WaitAny(eventHandles); if (handle == eWaitHandle.WAIT_TERMINATE) { break; } //else if (handle == eWaitHandle.WAIT_QUEUE) //no other possibilty left byte[] buf; while (samplesQ.TryDequeue(out buf)) { try { { int count = buf.Length; //Possible UDP Consumers //http://gqrx.dk/doc/streaming-audio-over-udp //nc -l -u -p 8765 | aplay -r 48000 -f S16_LE -t raw -c 1 //vlc --demux=rawaud --rawaud-channels=2 --rawaud-samplerate=48000 udp://@:8765 if (udpFlag) { udp.Send(buf, buf.Length); } if (muted) { Array.Clear(buf, 0, buf.Length); } writeSamples(buf); } } catch (Exception ex) { logger.Exception(ex); } } qEvent.Reset(); } Dispose(); logger.Debug(string.Format("Terminating thread {0} ... ", threadName)); }
private GroupBuilder(IEnumerable <TSource> source, IEqualityComparer <TKey> comparer, Func <TSource, TKey> keySelector, Func <TSource, TElement> resultSelector) { _enumerator = source.GetEnumerator(); _results = new SafeQueue <Grouping <TKey, TElement> >(); _proxies = new SafeDictionary <TKey, ProxyObservable <TElement> >(comparer); _keySelector = keySelector; _resultSelector = resultSelector; _cancellationTokenSource = new CancellationTokenSource(); }
protected virtual void Dispose(bool disposing) { // This is a protected method, the parameter should be kept GC.KeepAlive(disposing); _disposed = true; _canEnter.Dispose(); _asyncWaiters = null; _canEnter = null; }
/// <summary> /// Construct /// </summary> public CSocketConnect() { m_Socket = null; m_State = TNetState.NS_Null; m_QueMsgReceive = new SafeQueue(CNetStaticConfig.cnNetReceiveQueueSize); m_ReceiveByteBuff = new Byte[CNetStaticConfig.cnNetReceiveMsgByteSize]; m_nReceiveBuffPos = 0; m_nReceiveBuffReadLength = CNetStaticConfig.cnNetReceiveMsgByteSize; InitReceiveThread(); }
/// <summary> ///Dequeue 的测试 ///</summary> public void DequeueTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 ValueT expected = default(ValueT); // TODO: 初始化为适当的值 ValueT actual; actual = target.Dequeue(); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> ///GetEnumerator 的测试 ///</summary> public void GetEnumeratorTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 IEnumerator <ValueT> expected = null; // TODO: 初始化为适当的值 IEnumerator <ValueT> actual; actual = target.GetEnumerator(); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> ///CopyTo 的测试 ///</summary> public void CopyToTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 ValueT[] arrayT = null; // TODO: 初始化为适当的值 int iArrayIndex = 0; // TODO: 初始化为适当的值 target.CopyTo(arrayT, iArrayIndex); Assert.Inconclusive("无法验证不返回值的方法。"); }
/// <summary> ///ToArray 的测试 ///</summary> public void ToArrayTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 ValueT[] expected = null; // TODO: 初始化为适当的值 ValueT[] actual; actual = target.ToArray(); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> ///Contains 的测试 ///</summary> public void ContainsTestHelper <ValueT>() { SafeQueue <ValueT> target = new SafeQueue <ValueT>(); // TODO: 初始化为适当的值 ValueT value = default(ValueT); // TODO: 初始化为适当的值 bool expected = false; // TODO: 初始化为适当的值 bool actual; actual = target.Contains(value); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> /// Tx Queue beállítása /// </summary> /// <param name="txQueue"></param> public void SetTxQueue(SafeQueue <CommonCanMessage> txQueue) { foreach (var item in this) { foreach (var table in this) { var canTxTable = table.TableObject as CanTxMessageCollection; if (canTxTable != null) { canTxTable.TxQueue = txQueue; } } } }
private SemaphoreSlim(int initialCount, int?maxCount) { if (initialCount < 0 || initialCount > maxCount) { throw new ArgumentOutOfRangeException("initialCount", "initialCount < 0 || initialCount > maxCount"); } if (maxCount <= 0) { throw new ArgumentOutOfRangeException("initialCount", "maxCount <= 0"); } _maxCount = maxCount; _asyncWaiters = new SafeQueue <TaskCompletionSource <bool> >(); _count = initialCount; _event = new ManualResetEventSlim(_count > 0); }
public void SafeQueue_peek_works() { var q = new SafeQueue <string>(); Assert.IsNotNull(q); Assert.AreEqual(0, q.Count); q.Enqueue("a"); Assert.AreEqual(1, q.Count); var result = q.Peek(); Assert.AreEqual("a", result); result = q.Dequeue(); Assert.AreEqual("a", result); result = q.Dequeue(); Assert.AreEqual(null, result); }
public void SafeQueue_CantTellByDequeueIfQueueIsEmptyOrContainsNull() { var q = new SafeQueue <string>(); Assert.IsNotNull(q); Assert.AreEqual(true, q.IsEmpty); q.Enqueue(null); Assert.AreEqual(false, q.IsEmpty); var result2 = q.Peek(); Assert.AreEqual(null, result2); Assert.AreEqual(false, q.IsEmpty); result2 = q.Dequeue(); Assert.AreEqual(true, q.IsEmpty); Assert.AreEqual(null, result2); }
public Profiler( string profileDatabaseFolderPath, ProfileFileFrecuency profileFileFrecuency = ProfileFileFrecuency.Weekly, bool fullLogging = false, int maxProfileDatabaseFiles = 6, string profileDatabaseFileNamePrefix = "EntityLiteProfile-") { this.ProfileDatabaseFolderPath = profileDatabaseFolderPath; this.ProfileDatabaseFrecuency = profileFileFrecuency; this.MaxProfileDatabaseFiles = maxProfileDatabaseFiles; this.ProfileDatabaseFileNamePrefix = profileDatabaseFileNamePrefix; this.FullLogging = fullLogging; logItems = new SafeQueue <LogItem>(); signal = new AutoResetEvent(false); }
public Profiler( string profileDatabaseFolderPath, ProfileFileFrecuency profileFileFrecuency = ProfileFileFrecuency.Weekly, bool fullLogging = false, int maxProfileDatabaseFiles = 6, string profileDatabaseFileNamePrefix = "EntityLiteProfile-") { this.ProfileDatabaseFolderPath = profileDatabaseFolderPath; this.ProfileDatabaseFrecuency = profileFileFrecuency; this.MaxProfileDatabaseFiles = maxProfileDatabaseFiles; this.ProfileDatabaseFileNamePrefix = profileDatabaseFileNamePrefix; this.FullLogging = fullLogging; logItems = new SafeQueue<LogItem>(); signal = new AutoResetEvent(false); }
public Progressor(Progressor <T> wrapped) { if (wrapped == null) { throw new ArgumentNullException("wrapped"); } var control = 0; Predicate <T> newFilter = item => Thread.VolatileRead(ref control) == 0; var buffer = new SafeQueue <T>(); wrapped.SubscribeAction ( item => { if (newFilter(item)) { buffer.Add(item); } } ); _proxy = new ProxyObservable <T>(); _tryTake = (out T value) => { Interlocked.Increment(ref control); try { if (buffer.TryTake(out value) || wrapped.TryTake(out value)) { _proxy.OnNext(value); return(true); } else { _done = wrapped._done; return(false); } } finally { Interlocked.Decrement(ref control); } }; }
public void SafeQueue_isEmpty_works() { var q = new SafeQueue <string>(); Assert.IsNotNull(q); Assert.AreEqual(0, q.Count); Assert.AreEqual(true, q.IsEmpty); q.Enqueue("content"); Assert.AreEqual(false, q.IsEmpty); var result2 = q.Dequeue(); Assert.AreEqual("content", result2); Assert.AreEqual(true, q.IsEmpty); result2 = q.Dequeue(); Assert.AreEqual(true, q.IsEmpty); Assert.AreEqual(null, result2); }
public void SafeQueue_passedThroughQueueOperationContains_work() { var q = new SafeQueue <string>(5); Assert.IsNotNull(q); Assert.AreEqual(0, q.Count); q.Enqueue("a"); Assert.AreEqual(1, q.Count); q.Enqueue("b"); Assert.AreEqual(2, q.Count); q.Enqueue("c"); Assert.AreEqual(3, q.Count); Assert.IsTrue(q.Contains("a")); Assert.IsFalse(q.Contains("asdfawe")); var outval = q.Dequeue(); Assert.IsFalse(q.Contains("a")); }
public AdapterService( MessageTraceCollection tracer, ProjectParameters paramters, IAdapterStatistics adapterStat, MessageStatistics messageStat, Storage project, ToolTableCollection toolTables) { _messageTrace = tracer; _adapterStat = adapterStat; _messageStat = messageStat; _paramters = paramters; _project = project; _toolTables = toolTables; _txQueue = new SafeQueue <CommonCanMessage>(); }
public void SafeQueue_int_constructor_works() { var q = new SafeQueue <string>(5); Assert.IsNotNull(q); Assert.AreEqual(0, q.Count); q.Enqueue("a"); Assert.AreEqual(1, q.Count); q.Enqueue("b"); Assert.AreEqual(2, q.Count); q.Enqueue("c"); Assert.AreEqual(3, q.Count); q.Enqueue("d"); Assert.AreEqual(4, q.Count); q.Enqueue("e"); Assert.AreEqual(5, q.Count); q.Enqueue("f"); Assert.AreEqual(6, q.Count); }
static void TestQueue() { Thread[] threads = new Thread[8]; var queue = new SafeQueue<int>(); var signal = new AutoResetEvent(false); HashSet<int> integers = new HashSet<int>(); isRunning = true; Thread queueReader = new Thread(new ThreadStart(delegate { while (true) { signal.WaitOne(); int n; int count = 0; while (queue.Dequeue(out n)) { integers.Add(n); count++; } //Console.WriteLine(count); if (!isRunning) return; } })); queueReader.Start(); Action<int> enqueue = (s) => { for (int x = 0; x < 100000; x++) { queue.Enqueue(s + x); signal.Set(); if (x % 100 == 0) Thread.Yield(); } }; int start = 0; for (int i = 0; i < 8; i++) { threads[i] = new Thread(new ParameterizedThreadStart((state) => enqueue((int)state))); threads[i].Start(start); start += 100000; } for (int i = 0; i < 8; i++) { threads[i].Join(); } Thread.Yield(); isRunning = false; signal.Set(); queueReader.Join(); bool failed = false; for (int i = 0; i < 800000; i++) { if (!integers.Contains(i)) { //Console.WriteLine("{0} failed", i); failed = true; } } if (failed) Console.WriteLine("Test failed"); }