private void enqueue( T row, bool enqueue) { if (itemList == null) { itemList = new T[packageSize]; listPosition = -1; } if (enqueue) { itemList[++listPosition] = row; } if ( listPosition == (packageSize - 1) || (!enqueue)) { itemPackage ip = new itemPackage(itemList, listPosition); if (outputRows != null) { long writeLoc = outputRows.GetWriteLocation(); while (!ThreadCanceled) { if (outputRows.Write(writeLoc, ip)) { itemList = null; break; } else { //force a 1ms backoff if the slot is not available Thread.Sleep(1); } } } if (bulkRows != null) { long writeLoc = bulkRows.GetWriteLocation(); while (!ThreadCanceled) { if (bulkRows.Write(writeLoc, ip)) { itemList = null; break; } else { //force a 1ms backoff if the slot is not available Thread.Sleep(1); } } } } }
public bool MoveNext() { while (true) { if (result == null) { long readLoc = outputRows.GetReadLocation(); while (true) { if (outputRows.Read(readLoc, out result)) { currentResult = -1; break; } else { if (monitorExit) { return(false); } else { //no more rows to grab and we're here? might be time to exit. if (completionEvent.WaitOne(1)) { monitorExit = true; } if (mp.WorkerThreadException != null) { throw mp.WorkerThreadException; } Thread.Sleep(0); } } } } if (++currentResult > result.itemCount) { result = null; continue; } else { return(true); } } }
public bool Read() { while (true) { if (result == null) { long readLoc = bulkRows.GetReadLocation(); while (true) { if (bulkRows.Read(readLoc, out result)) { currentResult = -1; break; } else { if (monitorExit) { //need to send back a message to the monitor thread return(false); } else { //no more rows to grab and we're here? might be time to exit. if (bulkCompletionEvent.WaitOne(1)) { monitorExit = true; } //if the thread canceled flag is set, return true, so we can force an exception if (ThreadCanceled) { return(true); } } } } } if (++currentResult > result.itemCount) { result = null; continue; } else { return(true); } } }
public roundRobinBuffer(long bufferSize) { this.bufferSize = bufferSize; this.buffers = new itemPackage[bufferSize]; this.blank = new itemPackage(new T[0] { }, 0); for (long i = 0; i < bufferSize; i++) { buffers[i] = blank; } readLocation = -1; writeLocation = -1; }
public bool Read(long location, out itemPackage value) { return( (this.blank) != (value = Interlocked.Exchange <itemPackage>(ref buffers[location], this.blank))); }
public bool Write(long location, itemPackage value) { return( (this.blank) == Interlocked.CompareExchange <itemPackage>(ref buffers[location], value, this.blank)); }