Beispiel #1
0
//*************************************************************************************
//Panic button thread quits to the menu when pressed
//*************************************************************************************
static int PanicThread( SceSize args, void * argp )
{
	const u32 MASK = PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER | PSP_CTRL_START;

	u32 count = 0;

	//Loop 4 ever
	while(1)
	{
		SceCtrlData pad;
		sceCtrlPeekBufferPositive(&pad, 1);

		if( (pad.Buttons & MASK) == MASK )
		{
			 if(++count > 5)         //If button press for more that 2sec we return to main menu
			{
				count = 0;
				CGraphicsContext::Get()->ClearAllSurfaces();
				CPU_Halt("Panic");
				ThreadSleepMs(2000);
			}
		}
		else count = 0;

		//Idle here, only check button 3 times/sec not to hog CPU time from EMU
		ThreadSleepMs(300);
	}

	return 0;
}
void AudioPluginOSX::AudioSyncFunction(void * arg)
{
	AudioPluginOSX * plugin = static_cast<AudioPluginOSX *>(arg);
#if DEBUG_AUDIO
	static u64 last_time = 0;
	u64 now;
	NTiming::GetPreciseTime(&now);
	if (last_time == 0) last_time = now;
	DPF_AUDIO("VBL: %dms elapsed. Audio buffer len %dms\n", (s32)NTiming::ToMilliseconds(now-last_time), plugin->mBufferLenMs);
	last_time = now;
#endif

	u32 buffer_len = plugin->mBufferLenMs;	// NB: copy this volatile to a local var so that we have a consistent view for the remainder of this function.
	if (buffer_len > kMaxBufferLengthMs)
	{
		ThreadSleepMs(buffer_len - kMaxBufferLengthMs);
	}
}
Beispiel #3
0
  Buffer Port::Receive(std::size_t length, unsigned retries, unsigned delay)
  {
    Buffer buffer;
    Buffer data;

    unsigned retriesDone = 0;

    while (length > 0)
    {
      if (!Receive(buffer, length))
      {
        HandleAndClearPortError();
        throw PortReadFailed(*this, GetLastOSErrorText());
      }

      if (buffer.empty())
      {        
        retriesDone++;

        if (retriesDone == retries)
        {
          throw PortReadTimeout(*this);
        }

        ThreadSleepMs(delay);
      }
      else
      {
        data.insert(data.end(), buffer.begin(), buffer.end());

        length -= buffer.size();

        retriesDone = 0;
      }
    }

    assert(length == 0);
    assert(retriesDone < retries);

    return data;
  }
Beispiel #4
0
  void Port::Send(const Buffer& data, unsigned retries, unsigned delay) const
  {
    Buffer::const_iterator iter = data.begin();
    Buffer::const_iterator endIter = data.end();

    unsigned retriesDone = 0;

    while (iter != endIter)
    {
      Buffer::const_iterator oldPos = iter;

      if (!Send(iter, endIter))
      {
        HandleAndClearPortError();
        throw PortWriteFailed(*this, GetLastOSErrorText());
      }

      if (distance(oldPos, iter) == 0)
      {
        retriesDone++;

        if (retriesDone == retries)
        {
          throw PortWriteTimeout(*this);
        }

        ThreadSleepMs(delay);
      }
      else
      {
        // reset retry counter when data was sent
        retriesDone = 0;
      }
    }

    assert(iter == data.end());
    assert(retries > 0);
  }
void PauseSpinningThread(void) {
  ThreadSleepMs(10);
}