/// <summary> /// Creates new instance of <see cref="AtomicLong"/> /// </summary> /// <param name="initialValue">The value to store</param> /// <param name="order">Affects the way store operation occur. Load operations are always use <see cref="MemoryOrder.Acquire"/> semantics</param> public AtomicReference(T initialValue, MemoryOrder order = MemoryOrder.AcqRel) { order.ThrowIfNotSupported(); _instanceLock = order == MemoryOrder.SeqCst ? new object() : null; _order = order; this._value = initialValue; }
/// <summary> /// Creates new instance of <see cref="Atomic{T}"/> /// </summary> /// <param name="value">The value to store</param> /// <param name="order">Affects the way store operation occur. Default is <see cref="MemoryOrder.SeqCst"/> semantics which hurt performance</param> /// <param name="align">True to store the underlying value aligned, otherwise False</param> public Atomic(T value, MemoryOrder order = MemoryOrder.SeqCst, bool align = false) { order.ThrowIfNotSupported(); _storage = GetStorage(order, align); _order = order; _storage.Value = value; }
/// <summary> /// Creates new instance of <see cref="AtomicLongArray"/> /// </summary> /// <param name="length">The length of the underlying array</param> /// <param name="order">Affects the way store operation occur. Default is <see cref="MemoryOrder.AcqRel"/> semantics</param> public AtomicLongArray(long length, MemoryOrder order = MemoryOrder.SeqCst) { if (length < 0) { throw new ArgumentException("Length can't be negative"); } order.ThrowIfNotSupported(); _data = new long[length]; _order = order; }
/// <summary> /// Creates new instance of <see cref="AtomicLongArray"/> /// </summary> /// <param name="source">The array to copy elements from</param> /// <param name="order">Affects the way store operation occur. Default is <see cref="MemoryOrder.AcqRel"/> semantics</param> public AtomicLongArray(long[] source, MemoryOrder order = MemoryOrder.SeqCst) { if (source == null) { throw new ArgumentNullException("source"); } order.ThrowIfNotSupported(); _data = new long[source.Length]; _order = order; source.CopyTo(_data, 0); }
/// <summary> /// Creates new instance of <see cref="AtomicIntegerArray"/> /// </summary> /// <param name="length">The length of the underlying array</param> /// <param name="order">Affects the way store operation occur. Default is <see cref="MemoryOrder.AcqRel"/> semantics</param> public AtomicReferenceArray(int length, MemoryOrder order = MemoryOrder.SeqCst) { if (length < 0) { throw new ArgumentException("Length can't be negative"); } order.ThrowIfNotSupported(); _data = new T[length]; _order = order; _instanceLock = order == MemoryOrder.SeqCst ? new object() : null; }
/// <summary> /// Creates new instance of <see cref="AtomicIntegerArray"/> /// </summary> /// <param name="source">The array to copy elements from</param> /// <param name="order">Affects the way store operation occur. Default is <see cref="MemoryOrder.AcqRel"/> semantics</param> public AtomicReferenceArray(T[] source, MemoryOrder order = MemoryOrder.SeqCst) { if (source == null) { throw new ArgumentNullException("source"); } order.ThrowIfNotSupported(); _data = new T[source.Length]; _order = order; source.CopyTo(_data, 0); _instanceLock = order == MemoryOrder.SeqCst ? new object() : null; }
/// <summary> /// Creates new instance of <see cref="AtomicInteger"/> /// </summary> /// <param name="value">The value to store</param> /// <param name="order">Affects the way store operation occur. Load operations are always use <see cref="MemoryOrder.Acquire"/> semantics</param> /// <param name="align">True to store the underlying value aligned, otherwise False</param> public AtomicInteger(int value, MemoryOrder order = MemoryOrder.SeqCst, bool align = false) { order.ThrowIfNotSupported(); _order = order; if (align) { this._storage = BoxedInt32.Create(value); } else { this.acqRelValue = value; this._storage = BoxedInt32.Create(this); } }