/// <summary> /// Called to indicate that the latch completed and a later latch can start. /// </summary> public void Done() { _isCompleted = true; if (_later != null) { lock (_later) { Monitor.Pulse(_later); } } _earlier = null; _later = null; }
/// <summary> /// Ctor. /// </summary> /// <param name="name">the factory name</param> /// <param name="stateless">if set to <c>true</c> [stateless].</param> /// <param name="msecWait">the number of milliseconds latches will await maximually</param> /// <param name="locking">the blocking strategy to employ</param> /// <param name="timeSourceService">time source provider</param> public InsertIntoLatchFactory(String name, bool stateless, long msecWait, ConfigurationEngineDefaults.Threading.Locking locking, TimeSourceService timeSourceService) { _name = name; _msecWait = msecWait; _timeSourceService = timeSourceService; _stateless = stateless; _useSpin = (locking == ConfigurationEngineDefaults.Threading.Locking.SPIN); // construct a completed latch as an initial root latch if (_useSpin) { _currentLatchSpin = new InsertIntoLatchSpin(this); } else { _currentLatchWait = new InsertIntoLatchWait(this); } }
/// <summary>Returns a new latch. /// <para> /// Need not be synchronized as there is one per statement and execution is during statement lock. /// </para> /// </summary> /// <param name="payload">is the object returned by the await.</param> /// <returns>latch</returns> public Object NewLatch(EventBean payload) { if (_stateless) { return(payload); } if (_useSpin) { var nextLatch = new InsertIntoLatchSpin(this, _currentLatchSpin, _msecWait, payload); _currentLatchSpin = nextLatch; return(nextLatch); } else { var nextLatch = new InsertIntoLatchWait(_currentLatchWait, _msecWait, payload); _currentLatchWait.SetLater(nextLatch); _currentLatchWait = nextLatch; return(nextLatch); } }
private void ProcessThreadWorkQueueLatchedWait(InsertIntoLatchWait insertIntoLatch) { // wait for the latch to complete EventBean eventBean = insertIntoLatch.Await(); using (_unisolatedServices.EventProcessingRWLock.AcquireReadLock()) { try { ProcessMatches(eventBean); } catch (Exception) { LocalData.MatchesArrayThreadLocal.Clear(); throw; } finally { insertIntoLatch.Done(); } } Dispatch(); }
/// <summary> /// Hand a later latch to use for indicating completion via notify. /// </summary> /// <param name="later">is the later latch</param> public void SetLater(InsertIntoLatchWait later) { _later = later; }
/// <summary> /// Ctor - use for the first and unused latch to indicate completion. /// </summary> /// <param name="factory">The factory.</param> public InsertIntoLatchWait(InsertIntoLatchFactory factory) { _isCompleted = true; _earlier = null; _msecTimeout = 0; }
/// <summary> /// Ctor. /// </summary> /// <param name="earlier">the latch before this latch that this latch should be waiting for</param> /// <param name="msecTimeout">the timeout after which delivery occurs</param> /// <param name="payload">the payload is an event to deliver</param> public InsertIntoLatchWait(InsertIntoLatchWait earlier, long msecTimeout, EventBean payload) { _earlier = earlier; _msecTimeout = (int)msecTimeout; _payload = payload; }