Beispiel #1
0
ImgProcessingPool::ImgProcessingPool(std::auto_ptr<ImgProcessingThread> worker_thread, size_t max_threads/*= 0*/)
 : impl_(*(new Impl(worker_thread->GetFileCount())))
{
	impl_.max_threads_ = max_threads;
	impl_.pool_.push_back(worker_thread.release());
//	impl_.file_count_ = impl_.pool_.front().GetFileCount();

	if (impl_.file_count_ > 1)
	{
		size_t threads= GetLogicalProcessorCores();

		if (impl_.max_threads_ > 0 && threads > impl_.max_threads_)
			threads = impl_.max_threads_;

		if (threads > 1)
		{
			// divide work between cores

			if (impl_.file_count_ < threads)
				threads = static_cast<int>(impl_.file_count_);

			// create more threads (all suspended)
			for (int thread= 1; thread < threads; ++thread)
				impl_.pool_.push_back(impl_.pool_[0].Clone());
		}
	}
}