Exemplo n.º 1
0
	int ThreadPool::AddWork(ThreadPoolWork* pWork)
	{
		kpr::ScopedLock<kpr::Monitor> lock(*this);
		if (m_destroy)
		{
			return -1;
		}

		m_works.push_back(pWork);

		if (!WakeOneThread())
		{
			if (0 == m_maxCount || m_count < m_maxCount)
			{
				int step = m_step;

				if (0 < m_maxCount && m_count + m_step > m_maxCount)
				{
					step = m_maxCount - m_count;
				}

				AddThreads(step);
				WakeOneThread();
			}
		}

		return 0;
	}
Exemplo n.º 2
0
	ThreadPool:: ThreadPool (int count,
							 int minCount,
							 int maxCount,
							 int step,
							 int maxIdleTime,
							 int checkldleThreadsInterval)
	{
		m_destroy = false;
		m_minCount = minCount;
		m_maxCount = maxCount;
		m_maxIdleTime = maxIdleTime;
		m_count = 0;
		m_step = step;
		m_index = 0;

		m_lastRemoveIdleThreadsTime = GetCurrentTimeMillis();

		if (m_minCount <= 0)
		{
			m_minCount = MIN_THREAD_COUNT;
		}

		if (m_maxCount < 0)
		{
			m_maxCount = MAX_THREAD_COUNT;
		}

		if (m_maxIdleTime < 0)
		{
			m_maxIdleTime = MAX_IDLE_THREAD_TIME;
		}

		if (m_maxCount != 0 && m_maxCount < m_minCount)
		{
			m_minCount = MIN_THREAD_COUNT;
		}

		if ((m_maxCount != 0 && count > m_maxCount) || count < m_minCount)
		{
			count = m_minCount;
		}

		if (checkldleThreadsInterval < 0)
		{
			checkldleThreadsInterval = CHECK_IDLE_THREADS_INTERVAL;
		}

		AddThreads(count);

		m_manager = new ThreadPoolManage(this,checkldleThreadsInterval);
		m_manager->Start();
	}
Exemplo n.º 3
0
void JobManager::Initialize(int num_threads)
{
	m_running = true;
	AddThreads(num_threads);
}