{
const int BaseSize = 11;
- long bottom;
- long top;
- long upperBound;
+ int bottom;
+ int top;
+ int upperBound;
CircularArray<T> array = new CircularArray<T> (BaseSize);
public void PushBottom (T obj)
{
- /* Read is implemented as a simple load operation on 64bits
- * so no need to make the distinction ourselves
- */
- long b = Interlocked.Read (ref bottom);
+ int b = bottom;
var a = array;
// Take care of growing
var size = b - top - upperBound;
if (size > a.Size) {
- upperBound = Interlocked.Read (ref top);
+ upperBound = top;
a = a.Grow (b, upperBound);
array = a;
}
{
obj = default (T);
- long b = Interlocked.Decrement (ref bottom);
+ int b = Interlocked.Decrement (ref bottom);
var a = array;
- long t = Interlocked.Read (ref top);
- long size = b - t;
+ int t = top;
+ int size = b - t;
if (size < 0) {
// Set bottom to t
{
obj = default (T);
- long b = Interlocked.Decrement (ref bottom);
+ int b = Interlocked.Decrement (ref bottom);
var a = array;
- long t = Interlocked.Read (ref top);
- long size = b - t;
+ int t = top;
+ int size = b - t;
if (size < 0)
return false;
{
obj = default (T);
- long t = Interlocked.Read (ref top);
- long b = Interlocked.Read (ref bottom);
+ int t = top;
+ int b = bottom;
if (b - t <= 0)
return PopResult.Empty;
{
obj = default (T);
- long t = Interlocked.Read (ref top);
- long b = Interlocked.Read (ref bottom);
+ int t = top;
+ int b = bottom;
if (b - t <= 0)
return false;
public bool IsEmpty {
get {
- long t = Interlocked.Read (ref top);
- long b = Interlocked.Read (ref bottom);
+ int t = top;
+ int b = bottom;
return b - t <= 0;
}
}
this.segment = new T[size];
}
- public long Size {
+ public int Size {
get {
return size;
}
}
- public T this[long index] {
+ public T this[int index] {
get {
return segment[index % size];
}
}
}
- public CircularArray<T> Grow (long bottom, long top)
+ public CircularArray<T> Grow (int bottom, int top)
{
var grow = new CircularArray<T> (baseSize + 1);
- for (long i = top; i < bottom; i++) {
+ for (int i = top; i < bottom; i++) {
grow.segment[i] = segment[i % size];
}
return grow;
}
- public IEnumerable<T> GetEnumerable (long bottom, ref long top)
+ public IEnumerable<T> GetEnumerable (int bottom, ref int top)
{
- long instantTop = top;
+ int instantTop = top;
T[] slice = new T[bottom - instantTop];
int destIndex = -1;
- for (long i = instantTop; i < bottom; i++)
+ for (int i = instantTop; i < bottom; i++)
slice[++destIndex] = segment[i % size];
return RealGetEnumerable (slice, bottom, top, instantTop);
}
- IEnumerable<T> RealGetEnumerable (T[] slice, long bottom, long realTop, long initialTop)
+ IEnumerable<T> RealGetEnumerable (T[] slice, int bottom, int realTop, int initialTop)
{
int destIndex = (int)(realTop - initialTop - 1);
- for (long i = realTop; i < bottom; ++i)
+ for (int i = realTop; i < bottom; ++i)
yield return slice[++destIndex];
}
}
ManualResetEvent handle;
internal AtomicBooleanValue disposed;
int used;
- long state;
+ int state;
public ManualResetEventSlim ()
: this (false, 10)
long UpdateStateWithOp (bool set)
{
- long oldValue, newValue;
+ int oldValue, newValue;
do {
oldValue = state;
- newValue = (long)(((oldValue >> 1) + 1) << 1) | (set ? 1u : 0u);
+ newValue = (int)(((oldValue >> 1) + 1) << 1) | (set ? 1 : 0);
} while (Interlocked.CompareExchange (ref state, newValue, oldValue) != oldValue);
return newValue;
}
* we have a mismatch between S and H at the end because the last operations done were
* S3/H1. We thus need to repeat H3 to get to the desired final state.
*/
- long currentState;
+ int currentState;
do {
currentState = state;
if (currentState != stamp && (stamp & 1) != (currentState & 1)) {