Exemplo n.º 1
0
 // extra stuff
 public int Advance(int count)
 {
     lock (this)
     {
         int SizeLeft = count;
         while (SizeLeft > 0 && m_Size > 0)
         {
             if (m_RPos == BlockSize)
             {
                 m_RPos = 0;
                 FreeBlock((byte[])m_Blocks[0]);
                 m_Blocks.RemoveAt(0);
             }
             int ToFeed = m_Blocks.Count == 1 ? Math.Min(m_WPos - m_RPos, SizeLeft) : Math.Min(BlockSize - m_RPos, SizeLeft);
             m_RPos   += ToFeed;
             SizeLeft -= ToFeed;
             m_Size   -= ToFeed;
         }
         if (m_Size == 0)
         {
             //System.Diagnostics.Trace.WriteLine($"{Name} buffer empty");
             this.IsEmpty.Set();
             this.DataReady.Reset();
         }
         if (MaxLength - m_Size >= this.towrite)
         {
             //Trace.WriteLine("Advance, writeready.set()");
             WriteReady.Set();
         }
         return(count - SizeLeft);
     }
 }
Exemplo n.º 2
0
 public void Clear()
 {
     lock (this)
     {
         IsEmpty.Set();
         DataReady.Reset();
         WriteReady.Set();
         readclosevent.Reset();
         writecloseevent.Reset();
         foreach (byte[] block in m_Blocks)
         {
             FreeBlock(block);
         }
         m_Blocks.Clear();
         m_RPos = 0;
         m_WPos = 0;
         m_Size = 0;
         EOS.Reset();
     }
 }