コード例 #1
0
void Thread::runThread()
{
  char buffer[1024];
#if defined(_SYSTEM_WIN32_)
  icl_core::os::snprintf(buffer, 1023, "%s, %lu", getDescription().c_str(), threadId());
#elif defined(_SYSTEM_DARWIN_)
  icl_core::os::snprintf(buffer, 1023, "%s, %p", getDescription().c_str(), threadId().m_thread_id);
#else
  icl_core::os::snprintf(buffer, 1023, "%s, %lu", getDescription().c_str(), threadId().m_thread_id);
#endif
  m_thread_info = buffer;

  LOGGING_TRACE_CO(IclCoreThread, Thread, threadInfo(), "Begin." << endl);

  m_thread_mutex.lock();
  m_execute = true;
  m_starting = false;
  m_finished = false;

  // If this is actually a periodic thread, this call makes it periodic.
  // It this is a "normal" thread, this call does nothing.
  makePeriodic();

  // Call the run loop.
  run();

  m_execute = false;
  m_thread_mutex.unlock();
  m_finished = true;

  LOGGING_TRACE_CO(IclCoreThread, Thread, threadInfo(), "Done." << endl);
}
コード例 #2
0
void Thread::cancel()
{
  LOGGING_TRACE_CO(IclCoreThread, Thread, threadInfo(), "Begin." << endl);
  waitStarted();
  if (running())
  {
    LOGGING_DEBUG_CO(IclCoreThread, Thread,  threadInfo(), "Still running." << endl);
    m_execute = false;
    m_impl->cancel();
    m_finished = true;
  }
  LOGGING_DEBUG_CO(IclCoreThread, Thread, threadInfo(), "Done." << endl);
}
コード例 #3
0
bool Thread::wait(const icl_core::TimeStamp& until)
{
  bool success = false;

  if (m_joined)
  {
    return true;
  }

  waitStarted();

  if (m_finished)
  {
    success = true;
  }
  else if ((until == icl_core::TimeStamp::maxTime() && m_thread_mutex.lock())
           || m_thread_mutex.lock(until))
  {
    m_thread_mutex.unlock();
  }
  else if (icl_core::TimeStamp::now() < until)
  {
    LOGGING_ERROR_CO(IclCoreThread, Thread, threadInfo(),
                     "Thread is running and we should still wait, but LockMutex() returned unexpected."
                     "The wait function will now block further until the thread is really finished."
                     "But consider that your implementation could have a failure in locking ..." << endl);

    while (icl_core::TimeStamp::now() < until && !m_finished)
    {
      os::sleep(1);
    }
  }

  if (m_finished)
  {
    success = true;
  }

  if (success)
  {
    join();
    return true;
  }
  else
  {
    LOGGING_ERROR_CO(IclCoreThread, Thread, threadInfo(), "Wait not succesful." << endl);
    return false;
  }
}
コード例 #4
0
ファイル: MTMCScheduler.cpp プロジェクト: szli/MTMCSim
void MTMCScheduler::start()
{
    isTerminated = false;
    MCThreadInfo initInfo(nRunThreads, -1);
    MTMCSimulator->prepare(initInfo);

    RNGThread.reset(new thread(boost::bind(std::mem_fun<void, MTMCScheduler>(&MTMCScheduler::genRN),this)));
    

    

    for (unsigned int i = 0; i<nRunThreads; i++)
    {
        MCThreadInfo threadInfo(nRunThreads,i);
        MCRunThreads[i].reset(new thread
            (boost::bind(std::mem_fun<void, MTMCScheduler,MCThreadInfo>(&MTMCScheduler::oneThreadSimu),
            this, threadInfo)));
    }

    RNGThread->join();
    for (unsigned int i = 0; i<nRunThreads;i++)
        MCRunThreads[i]->join();

    MTMCSimulator->postProcess();
}
コード例 #5
0
ファイル: Autotune.cpp プロジェクト: ksnydertn/modplug
bool Autotune::Apply(double pitchReference, int targetNote)
//---------------------------------------------------------
{
	if(!CanApply())
	{
		return false;
	}

	const uint32 sampleFreq = sample.GetSampleRate(modType);
	// At the lowest frequency, we get the highest autocorrelation shift amount.
	const SmpLength maxShift = NoteToShift(sampleFreq, START_NOTE, pitchReference);
	if(!PrepareSample(maxShift))
	{
		return false;
	}
	// We don't process the autocorrelation overhead.
	const SmpLength processLength = sampleLength - maxShift;

	// Set up the autocorrelation threads
	SYSTEM_INFO sysInfo;
	GetSystemInfo(&sysInfo);
	const uint32 numProcs = std::max<uint32>(sysInfo.dwNumberOfProcessors, 1);
	const uint32 notesPerThread = (END_NOTE - START_NOTE + 1) / numProcs;
	std::vector<AutotuneThreadData> threadInfo(numProcs);
	std::vector<HANDLE> threadHandles(numProcs);

	for(uint32 p = 0; p < numProcs; p++)
	{
		threadInfo[p].pitchReference = pitchReference;
		threadInfo[p].sampleData = sampleData;
		threadInfo[p].processLength = processLength;
		threadInfo[p].sampleFreq = sampleFreq;
		threadInfo[p].startNote = START_NOTE + p * notesPerThread;
		threadInfo[p].endNote = START_NOTE + (p + 1) * notesPerThread;
		if(p == numProcs - 1)
			threadInfo[p].endNote = END_NOTE;

		threadHandles[p] = mpt::thread(AutotuneThread, &threadInfo[p]);
		ASSERT(threadHandles[p] != INVALID_HANDLE_VALUE);
	}

	WaitForMultipleObjects(numProcs, &threadHandles[0], TRUE, INFINITE);

	// Histogram for all notes.
	std::vector<uint64> autocorrHistogram(HISTORY_BINS, 0);

	for(uint32 p = 0; p < numProcs; p++)
	{
		for(int i = 0; i < HISTORY_BINS; i++)
		{
			autocorrHistogram[i] += threadInfo[p].histogram[i];
		}
		CloseHandle(threadHandles[p]);
	}

	// Interpolate the histogram...
	std::vector<uint64> interpolatedHistogram(HISTORY_BINS, 0);
	for(int i = 0; i < HISTORY_BINS; i++)
	{
		interpolatedHistogram[i] = autocorrHistogram[i];
		const int kernelWidth = 4;
		for(int ki = kernelWidth; ki >= 0; ki--)
		{
			// Choose bins to interpolate with
			int left = i - ki;
			if(left < 0) left += HISTORY_BINS;
			int right = i + ki;
			if(right >= HISTORY_BINS) right -= HISTORY_BINS;

			interpolatedHistogram[i] = interpolatedHistogram[i] / 2 + (autocorrHistogram[left] + autocorrHistogram[right]) / 2;
		}
	}

	// ...and find global minimum
	int minimumBin = 0;
	for(int i = 0; i < HISTORY_BINS; i++)
	{
		const int prev = (i > 0) ? (i - 1) : (HISTORY_BINS - 1);
		// Are we at the global minimum?
		if(interpolatedHistogram[prev] < interpolatedHistogram[minimumBin])
		{
			minimumBin = prev;
		}
	}

	// Center target notes around C
	if(targetNote >= 6)
	{
		targetNote -= 12;
	}

	// Center bins around target note
	minimumBin -= targetNote * BINS_PER_NOTE;
	if(minimumBin >= 6 * BINS_PER_NOTE)
	{
		minimumBin -= 12 * BINS_PER_NOTE;
	}
	minimumBin += targetNote * BINS_PER_NOTE;

	const double newFundamentalFreq = NoteToFrequency(static_cast<double>(69 - targetNote) + static_cast<double>(minimumBin) / BINS_PER_NOTE, pitchReference);

	sample.nC5Speed = Util::Round<uint32>(sample.nC5Speed * pitchReference / newFundamentalFreq);

	if((modType & (MOD_TYPE_XM | MOD_TYPE_MOD)) != 0)
	{
		sample.FrequencyToTranspose();
		if((modType & MOD_TYPE_MOD) != 0)
		{
			sample.RelativeTone = 0;
		}
	}

	return true;
}
コード例 #6
0
/*! Get the thread info, which consists of the thread description
 *  and the thread ID.
 *  \deprecated Obsolete coding style.
 */
const char *Thread::ThreadInfo() const
{
  return threadInfo();
}