/// <summary>Ctor - use for the first and unused latch to indicate completion. </summary> public InsertIntoLatchSpin(InsertIntoLatchFactory factory) { _factory = factory; _isCompleted = true; _earlier = null; _msecTimeout = 0; }
/// <summary> /// Ctor. /// </summary> /// <param name="factory">The factory.</param> /// <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 InsertIntoLatchSpin(InsertIntoLatchFactory factory, InsertIntoLatchSpin earlier, long msecTimeout, EventBean payload) { _factory = factory; _earlier = earlier; _msecTimeout = msecTimeout; _payload = payload; }
/// <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 ProcessThreadWorkQueueLatchedSpin(InsertIntoLatchSpin 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>Called to indicate that the latch completed and a later latch can start. </summary> public void Done() { _isCompleted = true; _earlier = null; }