<commit_before>
#include "threading_queue.h"

#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>

static void*
get_and_run( struct threading_queue* tq )
{
	struct function_queue_element fqe;

	do {
		if( !fq_pop( tq->fq, &fqe, 1 )) {
			fqe.func( fqe.arg );
		}

		usleep( tq->delay );
	} while( 1 );

	return 0;
}

int
tq_init( struct threading_queue* tq,
		struct threading_queue_startup_info tqsi[static 1] )
{
	int ret = 0;
	tq->fq = tqsi->fq;
	tq->max_threads = tqsi->max_threads;
	tq->delay = tqsi->delay;
	tq->threads = malloc( tqsi->max_threads * sizeof( pthread_t ));

	if( !tq->threads ) {
		ret = ENOMEM;
	}

	return ret;
}

int
tq_destroy( struct threading_queue* tq )
{
	int ret = tq_stop( tq );

	if( !ret ) {
		free( tq->threads );
	}

	return ret;
}

int
tq_start( struct threading_queue* tq )
{
	int ret = 0;
	unsigned i = 0;
	
	for( i = 0; i < tq->max_threads; ++i ) {
		if( !pthread_create( &tq->threads[i], 0,
					(void*(*)(void*)) get_and_run, tq )) {
			++ret;
		}
	}

	return ret;
}

int
tq_stop( struct threading_queue* tq )
{
	unsigned i = 0;

	for( i = 0; i < tq->max_threads; ++i ) {
		pthread_cancel( tq->threads[i] );
	}

	return 0;
}

<commit_msg>Changed tq_destroy so that it does not call tq_stop<commit_after>
#include "threading_queue.h"

#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>

static void*
get_and_run( struct threading_queue* tq )
{
	struct function_queue_element fqe;

	do {
		if( !fq_pop( tq->fq, &fqe, 1 )) {
			fqe.func( fqe.arg );
		}

		usleep( tq->delay );
	} while( 1 );

	return 0;
}

int
tq_init( struct threading_queue* tq,
		struct threading_queue_startup_info tqsi[static 1] )
{
	int ret = 0;
	tq->fq = tqsi->fq;
	tq->max_threads = tqsi->max_threads;
	tq->delay = tqsi->delay;
	tq->threads = malloc( tqsi->max_threads * sizeof( pthread_t ));

	if( !tq->threads ) {
		ret = ENOMEM;
	}

	return ret;
}

int
tq_destroy( struct threading_queue* tq )
{
	free( tq->threads );
	return 0;
}

int
tq_start( struct threading_queue* tq )
{
	int ret = 0;
	unsigned i = 0;
	
	for( i = 0; i < tq->max_threads; ++i ) {
		if( !pthread_create( &tq->threads[i], 0,
					(void*(*)(void*)) get_and_run, tq )) {
			++ret;
		}
	}

	return ret;
}

int
tq_stop( struct threading_queue* tq )
{
	unsigned i = 0;

	for( i = 0; i < tq->max_threads; ++i ) {
		pthread_cancel( tq->threads[i] );
	}

	return 0;
}


{'fraction_non_alphanumeric': 0.1550175712612261, 'fraction_numerical': 0.009761811792268645, 'mean_word_length': 2.6547788873038516, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 43, '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': '4181038', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1131, 'n_words': 248}