ProducerGetBuffer

INT8 *__stdcall ProducerGetBuffer(
        PRODUCER_CONSUMER_CONTEXT *Context,
        UINT64 RequestedSize,
        UINT64 BytesProcessed,
        PRODUCER_CONSUMER_WAIT_FLAGS Flags){
  __int64 v4; 
  char v5; 
  __int64 v6; 
  unsigned __int64 v8; 
  INT8 *result; 

  v4 = (unsigned int)BytesProcessed;
  v5 = Flags;
  v6 = (unsigned int)RequestedSize;
  while( _InterlockedCompareExchange(Context + 6, 1, 0) )
  {
    do
    {
      _mm_pause();
      PopHiberCheckForDebugBreak();
    }
    while( Context[6] );
  }
  while( 1 )
  {
    if( (unsigned int)v6 <= Context[14] + Context[2] - Context[8] )
    {
      v8 = *((_QWORD *)Context + 4);
      result = (INT8 *)(*(_QWORD *)Context + v8 % (unsigned int)Context[2]);
      *((_QWORD *)Context + 2) -= v4;
      *((_QWORD *)Context + 4) = v8 + v6;
      goto LABEL_4;
    }
    if( (v5 & 1) != 0 )
      break;
    Context[6] = 0;
    do
    {
      _mm_pause();
      PopHiberCheckForDebugBreak();
    }
    while( (unsigned int)v6 > Context[2] + Context[14] - Context[8] );
    while( _InterlockedCompareExchange(Context + 6, 1, 0) )
    {
      do
      {
        _mm_pause();
        PopHiberCheckForDebugBreak();
      }
      while( Context[6] );
    }
  }
  result = 0i64;
LABEL_4:
  Context[6] = 0;
  return result;
}

Referenced by:

PopCountDataAsProduced
PopRequestRead