Пример #1
0
void BufferQueue::Push(const byte* data, uint32 size)
{
    if (XTVERIFY(size > 0))
    {
        const uint32 startingSize = GetUsedSize();

        uint32 reserveSize = m_allocSize;
        while (startingSize + size + sizeof(uint32) >= reserveSize)
        {
            reserveSize *= 2;
        }

        Reserve(reserveSize);

        // Push the size of the message first
        WriteData(reinterpret_cast<byte*>(&size), sizeof(size));

        // Then push the data itself
        WriteData(data, size);

        const uint32 endSize = GetUsedSize();
        XTASSERT(endSize > startingSize);
        XTASSERT(endSize - startingSize == size + sizeof(size));
    }
}
Пример #2
0
	// This function should be only ran when the temporary buffer size is not 0 (otherwise, data is copied directly to the threads)
	bool CheckReceiveThreads()
	{
		SortReceiveThreads();

		bool wokeThreads = false;
		bool freedSpace = false;
		while (!receiveWaitingThreads.empty() && GetUsedSize() > 0)
		{
			MsgPipeWaitingThread *thread = &receiveWaitingThreads.front();
			// Receive as much as possible, even if it's not enough to wake up.
			u32 bytesToSend = std::min(thread->freeSize, GetUsedSize());

			thread->WriteBuffer(Memory::GetPointer(buffer), bytesToSend);
			// Put the unused data at the start of the buffer.
			nmp.freeSize += bytesToSend;
			memmove(Memory::GetPointer(buffer), Memory::GetPointer(buffer) + bytesToSend, GetUsedSize());
			freedSpace = true;

			if (thread->waitMode == SCE_KERNEL_MPW_ASAP || thread->freeSize == 0)
			{
				thread->Complete(GetUID(), 0);
				receiveWaitingThreads.erase(receiveWaitingThreads.begin());
				wokeThreads = true;
				thread = NULL;
			}
			// Stop at the first that can't wake up.
			else
				break;
		}

		if (freedSpace)
			wokeThreads |= CheckSendThreads();

		return wokeThreads;
	}
Пример #3
0
	bool CheckSendThreads()
	{
		SortSendThreads();

		bool wokeThreads = false;
		bool filledSpace = false;
		while (!sendWaitingThreads.empty() && nmp.freeSize > 0)
		{
			MsgPipeWaitingThread *thread = &sendWaitingThreads.front();
			u32 bytesToSend = std::min(thread->freeSize, (u32) nmp.freeSize);

			thread->ReadBuffer(buffer + GetUsedSize(), bytesToSend);
			nmp.freeSize -= bytesToSend;
			filledSpace = true;

			if (thread->waitMode == SCE_KERNEL_MPW_ASAP || thread->freeSize == 0)
			{
				thread->Complete(GetUID(), 0);
				sendWaitingThreads.erase(sendWaitingThreads.begin());
				wokeThreads = true;
				thread = NULL;
			}
			// Unlike receives, we don't do partial sends.  Stop at first blocked thread.
			else
				break;
		}

		if (filledSpace)
			wokeThreads |= CheckReceiveThreads();

		return wokeThreads;
	}
Пример #4
0
    bool FastCheck() const
    {
      if (Size <= sizeof(RawHeader))
      {
        return false;
      }
      const RawHeader& header = GetHeader();
      const uint_t endOfBlock = fromLE(header.LastSrcRestBytes) + 1;
      const uint_t lastBytesAddr = endOfBlock - LAST_BYTES_COUNT;
      const uint_t bitStreamAddr = lastBytesAddr - fromLE(header.SizeOfPacked);

      const uint_t srcPacked = fromLE(header.SrcPacked);
      if (bitStreamAddr == srcPacked)
      {
        //move forward
      }
      else if (lastBytesAddr == srcPacked + 1)
      {
        //move backward
      }
      else
      {
        return false;
      }
      const std::size_t usedSize = GetUsedSize();
      return Math::InRange(usedSize, sizeof(header), Size);
    }
Пример #5
0
void BufferQueue::Pop(Buffer& msg)
{
    const uint32 startingSize = GetUsedSize();

    // Read the size
    uint32 msgSize = 0;
    ReadData(reinterpret_cast<byte*>(&msgSize), sizeof(msgSize));

    msg.Reset(msgSize);
    byte* data = msg.GetData();

    // Read the message data
    ReadData(data, msgSize);

    // Record the message size
    msg.SetUsedSize(msgSize);

    const uint32 endSize = GetUsedSize();
    XTASSERT(startingSize > endSize);
    XTASSERT(startingSize - endSize == msgSize + sizeof(msgSize));
}
Пример #6
0
void BufferQueue::Reserve(uint32 newSize)
{
    if (newSize > m_allocSize)
    {
        byte* newBuffer = new byte[newSize];

        uint32 originalSize = GetUsedSize();

        // If startIndex and endIndex are equal, then there's no existing
        // data in the buffer to save

        // If the queue has not wrapped around...
        if (m_startIndex < m_endIndex)
        {
            uint32 copySize = m_endIndex - m_startIndex;
            XTASSERT(copySize <= m_allocSize);

            // Do a straight copy of the data to the start of the new buffer
            memcpy(newBuffer, m_data.get() + m_startIndex, copySize);
        }
        else if (m_endIndex < m_startIndex)
        {
            // The data wraps to the start of the buffer; do two copies
            uint32 startToEndSize = m_allocSize - m_startIndex;
            memcpy(newBuffer, m_data.get() + m_startIndex, startToEndSize);
            memcpy(newBuffer + startToEndSize, m_data.get(), m_endIndex);
        }

        m_data = newBuffer;
        m_startIndex = 0;
        m_endIndex = originalSize;
        m_allocSize = newSize;

        XTASSERT(GetUsedSize() == originalSize);
    }
}
Пример #7
0
bool TestUartSentDone(TxQueueInfo* info)
{

    /*Initializing and setting the variables*/

    int32_t test_return;
    info->head = 0;
    info->tail = (info->head + 1000) % TXQUEUE_SIZE;
    u16 used_size = GetUsedSize();

    /*Testing whether the function makes the queue empty as intended */

    if(used_size > LSIZE)
        info->bytes_wait_ack = LSIZE;
    else
        info->bytes_wait_ack= used_size;

    EndoUartInit(Senddone);
    Senddone();
    long double wait_time  =  200000;
    while (wait_time)
    {
        wait_time--;
    }

    if(info->is_sending_lower != 0 || info->head != info->tail)
    {
        xil_printf("The function is not making the queue empty as"
                   " intended\n\r");
        return ENDO_FAILURE;
    }


    /*Testing if the function works properly if a null pointer is passed*/

    info = NULL;
    test_return = UartSentDone(info);

    if(test_return != -1)
    {
        xil_printf("The return value in case of NULL pointer passed "
                   "is not correct.....\n\r");
        return ENDO_FAILURE;
    }
    xil_printf("T");
    return ENDO_SUCCESS;

}
void DebugGlyphContainer( unsigned int atlasSize,
                          StatusSet statusSet,
                          StatusPointerSet deadSet)
{
  std::cout <<"----- Glyph Status Container --- " << std::endl;

  for( StatusSet::iterator iter = statusSet.begin(); iter != statusSet.end(); ++iter)
  {
    const GlyphStatus& status( (*iter) );
    std::cout << " Character " << status.GetCharacterCode() <<" \""<< (char)status.GetCharacterCode() << "\"";
    std::cout << ", Font " << status.GetFontId();

    OutputStatus(status);
    if( status.GetRefCount() )
    {
      std::cout << ", Ref count: "<< status.GetRefCount()  << std::endl;
    }
    else
    {
      std::cout << ", Ref count: 0 : ~DEAD~"  << std::endl;
    }
  }

  std::cout <<" ------------------- " << std::endl;
  std::cout <<" -----Dead List------ " << std::endl;

  for( StatusPointerSet::iterator iter = deadSet.begin(); iter != deadSet.end(); ++iter)
  {
    const GlyphStatus* status( (*iter) );
    std::cout << " Character " << status->GetCharacterCode() <<" \""<< (char)status->GetCharacterCode() << "\"";
    std::cout << ", Font " << status->GetFontId();
    std::cout << ", Ref count: "<< status->GetRefCount();

    OutputStatus(*status);

    std::cout << ", Dead Time: "<< status->GetDeadTime()  << std::endl;
  }
  std::cout <<" ------------------- " << std::endl;
  std::cout <<" Atlas Size: "<< atlasSize << ", Used Space " << GetUsedSize(statusSet);
  std::cout <<", Dead size (cached): "<< deadSet.size() << std::endl;
  std::cout <<" ------------------- " << std::endl;

};
Пример #9
0
 bool FastCheck() const
 {
   if (Size < sizeof(typename Version::RawHeader))
   {
     return false;
   }
   const typename Version::RawHeader& header = GetHeader();
   const DataMovementChecker checker(fromLE(header.PackedDataSrc), 
     fromLE(header.PackedDataDst), fromLE(header.PackedDataSize), header.PackedDataCopyDirection);
   if (!checker.IsValid())
   {
     return false;
   }
   const uint_t usedSize = GetUsedSize();
   if (usedSize > Size)
   {
     return false;
   }
   return true;
 }
Пример #10
0
bool TestGetUsedSize(TxQueueInfo* info)
{
    u16 test_return;

    /*Testing the values for used space according to various logics*/

    info->head = 0;
    info->tail = TXQUEUE_SIZE - 2;

    test_return = GetUsedSize(info);

    if(test_return != (TXQUEUE_SIZE - 2))
    {
        xil_printf("The Function get Free Available size not returning"
                   " correct value\n\r");
        return ENDO_FAILURE;
    }

    info->head = 0;
    info->tail = TXQUEUE_SIZE / 2;

    test_return = GetUsedSize(info);

    if(test_return != (TXQUEUE_SIZE / 2))
    {
        xil_printf("The Function get Free Available size not returning"
                   " correct value\n\r");
        return ENDO_FAILURE;
    }

    /*Testing when the data is rolled over whether the function behaves
     * correctly or not*/

    u16 some_no = TXQUEUE_SIZE / 2;
    info->tail = TXQUEUE_SIZE - some_no;
    info->head = some_no % TXQUEUE_SIZE;

    test_return = GetUsedSize(info);

    if(test_return != (TXQUEUE_SIZE - (2 * some_no)))
    {
        xil_printf("The Function get Free Available size not returning"
                   " correct value\n\r");
        return ENDO_FAILURE;
    }


    /*Testing if the function works properly if a null pointer is passed*/

    info = NULL;
    test_return = GetFreeAvailableSize(info);

    if(test_return != 0Xffff)
    {
        xil_printf("The return value incase of NULL pointer passed "
                   "is not correct.....\n\r");
        return ENDO_FAILURE;
    }

    return ENDO_SUCCESS;

}
Пример #11
0
bool DynamicMemoryBlockBase::Alloc()
{
	return AllocAlign(GetSize() - GetUsedSize()) != 0;
}