Class NamedInterlocked
Provides functionality similar to the Interlocked class executed over a named slot.
All operations are THREAD-SAFE for calling concurrently.
The name comparison is that of Registry's which is OrdinalIgnoreCase.
This class was designed to better organize named counters incremented from different threads,
i.e. this is needed to keep a count of calls to remote host identified by their names.
This class is NOT designed for frequent additions/deletions of named slots, nor was it designed
to keep millions of slots. Use it in cases when there are thousands at most slots and new slots
appear infrequently. You must delete unneeded slots
Inheritance
System.Object
NamedInterlocked
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Azos.dll
Syntax
public sealed class NamedInterlocked
Properties
AllNames
Enumerates all slot names. This operation is thread-safe, and returns a snapshot of the instance taken at the time of the first call
Declaration
public IEnumerable<string> AllNames { get; }
Property Value
Type |
Description |
System.Collections.Generic.IEnumerable<System.String> |
|
Count
Returns the current number of named slots in the instance
Declaration
public int Count { get; }
Property Value
Type |
Description |
System.Int32 |
|
Methods
Add(NamedInterlocked, Nullable<Int64>)
Adds slot snapshot from another source.
Pass exchange to flip the existing slots to the exchanged value
Declaration
public void Add(NamedInterlocked source, long? exchangeSource = default(long? ))
Parameters
Type |
Name |
Description |
NamedInterlocked |
source |
|
System.Nullable<System.Int64> |
exchangeSource |
|
Add(Amount)
Declaration
public Amount Add(Amount arg)
Parameters
Type |
Name |
Description |
Amount |
arg |
|
Returns
AddLong(String, Int64)
Declaration
public long AddLong(string name, long arg)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Int64 |
arg |
|
Returns
Type |
Description |
System.Int64 |
|
Clear()
Deletes all state for all slots
Declaration
Clear(String)
Deletes all state for the named slot returning true if the slot was found and removed
Declaration
public bool Clear(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Boolean |
|
DecrementLong(String)
Declaration
public long DecrementLong(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Int64 |
|
ExchangeLong(String, Int64)
Captures the current value of a named long value and atomically sets it to the passed value
Declaration
public long ExchangeLong(string name, long value)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Int64 |
value |
|
Returns
Type |
Description |
System.Int64 |
|
Exists(String)
Returns true when the instance contains the named slot
Declaration
public bool Exists(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Boolean |
|
IncrementLong(String)
Declaration
public long IncrementLong(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Int64 |
|
ReadAtomicLong(String)
Returns a 64-bit value, loaded as an atomic operation even on a 32bit platform
Declaration
public long ReadAtomicLong(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Int64 |
|
SnapshotAllAmounts(Nullable<Decimal>)
Enumerates all named amounts. This operation is thread-safe, and returns a snapshot of the instance taken at the time of the first call
If exchange is specified, atomically flips the value of every slot
Declaration
public IEnumerable<KeyValuePair<string, Amount>> SnapshotAllAmounts(decimal? exchange = default(decimal? ))
Parameters
Type |
Name |
Description |
System.Nullable<System.Decimal> |
exchange |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, Amount>> |
|
SnapshotAllLongs(Nullable<Int64>)
Enumerates all named integers. This operation is thread-safe, and returns a snapshot of the instance taken at the time of the first call.
If exchange is specified, atomically flips the value of every slot
Declaration
public IEnumerable<KeyValuePair<string, long>> SnapshotAllLongs(long? exchange = default(long? ))
Parameters
Type |
Name |
Description |
System.Nullable<System.Int64> |
exchange |
|
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, System.Int64>> |
|
SnapshotAllLongsInto<TDatum>(IInstrumentation, Nullable<Int64>)
Records a snapshot of all longs converted into TDatum. The TDatum must have a public .ctor(string, long) or runtime exception is thrown
(this is because C# does not have a contract/constraint for parameterized constructors)
Declaration
public void SnapshotAllLongsInto<TDatum>(IInstrumentation instrumentation, long? exchange = default(long? ))
where TDatum : Datum
Parameters
Type |
Name |
Description |
IInstrumentation |
instrumentation |
|
System.Nullable<System.Int64> |
exchange |
|
Type Parameters
VolatileReadLong(String)
Captures the current value of a named long value.
If slot does not exist, creates it and captures the value (which may be non-zero even if the slot was just created)
Declaration
public long VolatileReadLong(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Int64 |
|
Extension Methods