public int OutPre(ManagedPointer<byte> head, int length)
{
if (status != 0) return 0;
//while ( (is_ining) || (is_outing) ) Mai_Sleep(1);
//is_outing = 1;
#if BIT_READER_THREAD_SAFE
lock (this)
#endif
{
byte[] @base = this.@base;
int rear = this.rear;
int front = this.front;
int max_size = this.max_size;
int space = (rear - front + max_size) % max_size;
int copy_length = (length > space) ? space : length;
int ato = max_size - front;
int copy1 = (copy_length > ato) ? ato : copy_length;
int copy2 = (copy_length > ato) ? (copy_length - ato) : 0;
if (copy1 != 0)
{
head.Memcpy(@base.GetPointer(front), copy1);
front = (front + copy1) % max_size;
head += copy1;
}
if (copy2 != 0)
{
head.Memcpy(@base.GetPointer(front), copy2);
front = (front + copy2) % max_size;
head += copy2;
}
//this.front = front;
//is_outing = 0;
return copy_length;
}
}