<commit_before>#include "Crown.h"
#include "EventBuffer.h"
#include "OsTypes.h"
#include "Mouse.h"
#include "Log.h"

using namespace crown;

//-----------------------------------------------------------------------------
int main()
{
	EventBuffer buffer;

	OsMouseEvent ome;
	ome.button = MouseButton::LEFT;
	ome.x = 0;
	ome.y = 0;
	ome.pressed = true;

	buffer.push_event((uint32_t)OsEvent::MOUSE, &ome, sizeof(OsMouseEvent));

	OsEvent::Enum type = (OsEvent::Enum)buffer.get_next_event_type();
	Log::d("type: %d", type);

	OsMouseEvent* result;
	uint32_t et; size_t es;
	result = (OsMouseEvent*)buffer.get_next_event(et, es);

	Log::d("button: %d", result->button);
	Log::d("x: %d", result->x);
	Log::d("y: %d", result->y);
	Log::d("pressed: %d", result->pressed);

	return 0;
}<commit_msg>add test for EventBuffer<commit_after>#include <cstdlib>
#include <ctime>

#include "Crown.h"
#include "EventBuffer.h"
#include "OsTypes.h"
#include "Mouse.h"
#include "OsThread.h"
#include "Log.h"

using namespace crown;

EventBuffer* g_buffer_1;
EventBuffer* g_buffer_2;
EventBuffer* g_tmp;

OsThread g_thread("consumer-thread");
Semaphore g_process_sem;
Semaphore g_thread_sem;

bool g_exit = false;

//-----------------------------------------------------------------------------
void push_event()
{
	uint32_t x = (rand() % 100) + 1;
	uint32_t y = (rand() % 100) + 1;

	OsMouseEvent ome;
	ome.button = MouseButton::LEFT;
	ome.x = x;
	ome.y = y;
	ome.pressed = true;

	g_buffer_1->push_event((uint32_t)OsEvent::MOUSE, &ome, sizeof(OsMouseEvent));
	Log::i("Event pushed");
}

//-----------------------------------------------------------------------------
void swap()
{
	g_tmp = g_buffer_1;
	g_buffer_1 = g_buffer_2;
	g_buffer_2 = g_tmp;
	Log::i("Buffers swapped");
}

//-----------------------------------------------------------------------------
int32_t thread_proc(void* /*user_data*/)
{
	OsMouseEvent* result;
	uint32_t et; size_t es;

	while (true)
	{
		while (!g_buffer_1->is_empty())
		{
			result = (OsMouseEvent*)g_buffer_1->get_next_event(et, es);

			if (result != NULL)
			{
				Log::d("x: %d, y: %d", result->x, result->y);
			}
			else
			{
				g_buffer_1->clear();

				swap();

				g_process_sem.post();
				g_thread_sem.wait();
			}
		}
	}

	return 0;
}

//-----------------------------------------------------------------------------
int main()
{
	memory::init();
	srand(time(NULL));

	g_buffer_1 = CE_NEW(default_allocator(), EventBuffer);
	g_buffer_2 = CE_NEW(default_allocator(), EventBuffer);

	g_thread.start(thread_proc);

	while (!g_exit)
	{
		push_event();

		g_thread_sem.post();
		g_process_sem.wait();
	}

	g_thread.stop();

	memory::shutdown();

	return 0;
}
{'fraction_non_alphanumeric': 0.29631010063361907, 'fraction_numerical': 0.014535967200894522, 'mean_word_length': 2.355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '7284241', 'n_tokens_mistral': 1042, 'n_tokens_neox': 965, 'n_words': 185}