<commit_before>#pragma once

#include "blockingQueue.h"

#include <thread>
#include <atomic>
#include <pthread.h>

namespace threadPool {

template<typename T>
class ThreadPool final {
private:
	BlockingQueue<T> blockingQueue;
	std::mutex countMutex;
	int        count;
	std::condition_variable queueIsEmpty;
	std::mutex threadCountMutex;
	int        threadCount;
	std::atomic_bool finish;
	std::condition_variable threadIsEmpty;

public:
	ThreadPool()
		: count(0)
		, threadCount(0)
		, finish(false)
	{}

	/*
	 * Will abort all threads and open jobs
	 */
	~ThreadPool() {
		std::unique_lock<std::mutex> lock(threadCountMutex);
		finish = true;
		blockingQueue.forceFinish();
		if (threadCount > 0) {
			threadIsEmpty.wait(lock);
		}
	}

	/**
	 * This will queue a new object, but will not block
	 */
	void queue(T t) {
		std::unique_lock<std::mutex> lock(countMutex);
		++count;
		blockingQueue.queue(t);
	}

	/**
	 * Wait till queue is empty
	 *
	 */
	void wait() {
		std::unique_lock<std::mutex> lock(countMutex);
		if (count > 0) {
			queueIsEmpty.wait(lock);
		}
	}

	/**
	 * Spawns new threads that can work on a job
	 * This function should only be called once
	 *
	 * @TODO multiple calls of this function will lead to more and more threads,
	 *       because they never exit.
	 * @TODO This function can only be called when there are no jobs in the queue
	 *
	 * @_f           function that the threads should execute
	 * @_threadCount number of threads that should be spawned
	 */
	void spawnThread(std::function<void(T t)> _f, int _threadCount) {
		std::unique_lock<std::mutex> lock(threadCountMutex);
		threadCount += _threadCount;

		for (int i(0); i < _threadCount; ++i) {<commit_msg>adding queueContainer, to queue std::list, std::set, std::vector, etc...<commit_after>#pragma once

#include "blockingQueue.h"

#include <thread>
#include <atomic>
#include <pthread.h>

namespace threadPool {

template<typename T>
class ThreadPool final {
private:
	BlockingQueue<T> blockingQueue;
	std::mutex countMutex;
	int        count;
	std::condition_variable queueIsEmpty;
	std::mutex threadCountMutex;
	int        threadCount;
	std::atomic_bool finish;
	std::condition_variable threadIsEmpty;

public:
	ThreadPool()
		: count(0)
		, threadCount(0)
		, finish(false)
	{}

	/*
	 * Will abort all threads and open jobs
	 */
	~ThreadPool() {
		std::unique_lock<std::mutex> lock(threadCountMutex);
		finish = true;
		blockingQueue.forceFinish();
		if (threadCount > 0) {
			threadIsEmpty.wait(lock);
		}
	}

	/**
	 * This will queue a new object, but will not block
	 */
	void queue(T t) {
		std::unique_lock<std::mutex> lock(countMutex);
		++count;
		blockingQueue.queue(t);
	}

	/**
	 * This function will queue full range, but will not block
	 */
	template<typename C>
	void queueContainer(C const& c) {
		for (T const& t : c ) {
			queue(t);
		}
	}

	/**
	 * Wait till queue is empty
	 *
	 */
	void wait() {
		std::unique_lock<std::mutex> lock(countMutex);
		if (count > 0) {
			queueIsEmpty.wait(lock);
		}
	}

	/**
	 * Spawns new threads that can work on a job
	 * This function should only be called once
	 *
	 * @TODO multiple calls of this function will lead to more and more threads,
	 *       because they never exit.
	 * @TODO This function can only be called when there are no jobs in the queue
	 *
	 * @_f           function that the threads should execute
	 * @_threadCount number of threads that should be spawned
	 */
	void spawnThread(std::function<void(T t)> _f, int _threadCount) {
		std::unique_lock<std::mutex> lock(threadCountMutex);
		threadCount += _threadCount;

		for (int i(0); i < _threadCount; ++i) {
{'fraction_non_alphanumeric': 0.11946050096339114, 'fraction_numerical': 0.0027525461051472614, 'mean_word_length': 3.6829896907216493, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3598630', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1182, 'n_words': 359}