public void AttachConsumer(IConsumer consumer) { if (!consumer.AcceptType.IsAssignableFrom(ValueType)) { throw new ArgumentException($"Type not match, streamer value type: {ValueType}, consumer accept type: {consumer.AcceptType}"); } using (_consumersLock.AcquireWriteLock()) if (!Insert(_consumers, consumer)) { throw new ArgumentException("The given consumer is already attached"); } }
internal V GetOrSet <V, S>(UserDataSlot <V> slot, ref S valueFactory) where S : struct, ISupplier <V> { V userData; //fast path - read user data if it is already exists //do not use UpgradeableReadLock due to performance reasons using (synchronizer.AcquireReadLock()) { if (slot.GetUserData(this, out userData)) { return(userData); } } //non-fast path, no user data presented using (synchronizer.AcquireWriteLock()) { if (!slot.GetUserData(this, out userData)) { slot.SetUserData(this, userData = valueFactory.Supply()); } return(userData); } }
public Task <BoolResult> UpdateRingAsync(OperationContext context, ClusterState clusterState) { // This is a CPU intensive operation and is called from the Heartbeat so we don't want to consume the calling thread return(context.PerformOperationAsync(Tracer, () => Task.Run(() => { RingNode[] newRing = CreateNewRing(clusterState); using (_ringLock.AcquireWriteLock()) { _ring = newRing; }; return BoolResult.Success; }) )); }
public void InvalidateMetricDefinition(IMetricDefinition metricDefinition) { using (readerWriterLock.AcquireWriteLock()) metricDefinitions.Remove(metricDefinition); }