<commit_before>#include <unistd.h>
#include <string.h>
#include <iostream>

#include "display_driver.h"

// static inits
bool display_driver::terminate = false;
display_driver * display_driver::instance_p = NULL;

display_driver::display_driver()
{
	mover_p = new spi_mover("/dev/spidev0.0");

	for(int i = 0; i < NUM_STRINGS; i++)
	{
		strings[i] = new string_cb(CHARS_PER_STRING);
	}
	
	pthread_mutex_init(&data_mutex, NULL);
	
	// spawn a thread
	display_driver::terminate = false;
	pthread_create(&worker_thread, // thread structure
					NULL, 			// attributes
					&thread_func,	// body
					NULL);			// argv
					
	instance_p = this;
}

display_driver::~display_driver()
{

	display_driver::terminate = true;
	
	pthread_join(worker_thread, NULL);

	delete mover_p;
}

		
bool display_driver::update_string(int index, char * new_string)
{
	bool retval = true;

	pthread_mutex_lock(&data_mutex);
	
	if(index >= NUM_STRINGS)
	{
		std::cerr << "Display Error: Invalid string index requested: " << index << std::endl;
		goto cleanup;
	}
	
	strings[index]->replace_string(new_string);
	
cleanup:	
	pthread_mutex_unlock(&data_mutex);
	<commit_msg>Fixed display destructor<commit_after>#include <unistd.h>
#include <string.h>
#include <iostream>

#include "display_driver.h"

// static inits
bool display_driver::terminate = false;
display_driver * display_driver::instance_p = NULL;

display_driver::display_driver()
{
	mover_p = new spi_mover("/dev/spidev0.0");

	for(int i = 0; i < NUM_STRINGS; i++)
	{
		strings[i] = new string_cb(CHARS_PER_STRING);
	}
	
	pthread_mutex_init(&data_mutex, NULL);
	
	// spawn a thread
	display_driver::terminate = false;
	pthread_create(&worker_thread, // thread structure
					NULL, 			// attributes
					&thread_func,	// body
					NULL);			// argv
					
	instance_p = this;
}

display_driver::~display_driver()
{
	display_driver::terminate = true;
	
	pthread_join(worker_thread, NULL);

	for(int i = 0; i < NUM_STRINGS; i++)
	{
		strings[i] = new string_cb(CHARS_PER_STRING);
	}

	pthread_mutex_destroy(&data_mutex);
	
	delete mover_p;
}

		
bool display_driver::update_string(int index, char * new_string)
{
	bool retval = true;

	pthread_mutex_lock(&data_mutex);
	
	if(index >= NUM_STRINGS)
	{
		std::cerr << "Display Error: Invalid string index requested: " << index << std::endl;
		goto cleanup;
	}
	
	strings[index]->replace_string(new_string);
	
cleanup:	
	pthread_mutex_unlock(&data_mutex);
	
{'fraction_non_alphanumeric': 0.13311421528348397, 'fraction_numerical': 0.002875924404272802, 'mean_word_length': 4.534090909090909, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 13, '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': '4613084', 'n_tokens_mistral': 961, 'n_tokens_neox': 872, 'n_words': 170}