<commit_before>/*
 *	author: <NAME> <<EMAIL>>
 *
 *	Use of this source code is governed by the MIT license that can be
 *	found in the LICENSE file.
 */


#include "thread.h"
#include "muggle/c/base/err.h"

#if MUGGLE_PLATFORM_WINDOWS

int muggle_thread_create(muggle_thread_t *thread, muggle_thread_routine routine, void *args)
{
	thread->handle = (HANDLE)_beginthreadex(
		NULL, 0, routine, args, 0, &thread->id);
	if (thread->handle == NULL)
	{
		return MUGGLE_ERR_SYS_CALL;
	}

	return MUGGLE_OK;
}

int muggle_thread_join(muggle_thread_t *thread)
{
	if (WaitForSingleObject(thread->handle, INFINITE) == WAIT_FAILED)
	{
		return MUGGLE_ERR_SYS_CALL;
	}

	if (!CloseHandle(thread->handle))
	{
		return MUGGLE_ERR_SYS_CALL;
	}

	return MUGGLE_OK;
}

int muggle_thread_detach(muggle_thread_t *thread)
{<commit_msg>fix warning in thread in windows<commit_after>/*
 *	author: <NAME> <<EMAIL>>
 *
 *	Use of this source code is governed by the MIT license that can be
 *	found in the LICENSE file.
 */


#include "thread.h"
#include "muggle/c/base/err.h"

#if MUGGLE_PLATFORM_WINDOWS

#include <process.h>

int muggle_thread_create(muggle_thread_t *thread, muggle_thread_routine routine, void *args)
{
	thread->handle = (HANDLE)_beginthreadex(
		NULL, 0, routine, args, 0, &thread->id);
	if (thread->handle == NULL)
	{
		return MUGGLE_ERR_SYS_CALL;
	}

	return MUGGLE_OK;
}

int muggle_thread_join(muggle_thread_t *thread)
{
	if (WaitForSingleObject(thread->handle, INFINITE) == WAIT_FAILED)
	{
		return MUGGLE_ERR_SYS_CALL;
	}

	if (!CloseHandle(thread->handle))
	{
		return MUGGLE_ERR_SYS_CALL;
	}

	return MUGGLE_OK;
}

int muggle_thread_detach(muggle_thread_t *thread)
{
{'fraction_non_alphanumeric': 0.118491921005386, 'fraction_numerical': 0.0023937761819269898, 'mean_word_length': 5.014388489208633, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 20, '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': '6922586', 'n_tokens_mistral': 701, 'n_tokens_neox': 666, 'n_words': 145}