<commit_before>/**
 * @file
 *
 * @brief
 *
 * @date 21.06.2013
 * @author <NAME>
 */

#include <kernel/thread.h>

#include <embox/unit.h>

#include <mem/misc/pool.h>

#include <kernel/thread/thread_alloc.h>


#define STACK_SZ      OPTION_GET(NUMBER, thread_stack_size)
#define POOL_SZ       OPTION_GET(NUMBER, thread_pool_size)

typedef union thread_pool_entry {
	struct thread thread;
	char stack[STACK_SZ];
} thread_pool_entry_t __attribute__((aligned(STACK_SZ)));

POOL_DEF(thread_pool, thread_pool_entry_t, POOL_SZ);

struct thread *thread_alloc(void) {
	thread_pool_entry_t *block;
	struct thread *t;

	if (!(block = (thread_pool_entry_t *) pool_alloc(&thread_pool))) {
		return NULL;
	}

	t = &block->thread;

	thread_stack_init(t, STACK_SZ);

	return t;
}

void thread_free(struct thread *t) {
	thread_pool_entry_t *block;

	assert(t != NULL);

	// TODO may be this is not the best way... -- Eldar
	block = member_cast_out(t, thread_pool_entry_t, thread);
	pool_free(&thread_pool, block);
}<commit_msg>sched: debug: poisoning thread area upon alloc/free<commit_after>/**
 * @file
 * @brief
 *
 * @date 21.06.2013
 * @author <NAME>
 */

#include <kernel/thread/thread_alloc.h>

#include <kernel/thread.h>
#include <mem/misc/pool.h>


#define STACK_SZ      OPTION_GET(NUMBER, thread_stack_size)
#define POOL_SZ       OPTION_GET(NUMBER, thread_pool_size)

typedef union thread_pool_entry {
	struct thread thread;
	char stack[STACK_SZ];
} thread_pool_entry_t __attribute__((aligned(STACK_SZ)));

POOL_DEF(thread_pool, thread_pool_entry_t, POOL_SZ);

struct thread *thread_alloc(void) {
	thread_pool_entry_t *block;
	struct thread *t;

	if (!(block = (thread_pool_entry_t *) pool_alloc(&thread_pool))) {
		return NULL;
	}
	memset(block, 0x53, sizeof(*block));

	t = &block->thread;

	thread_stack_init(t, STACK_SZ);

	return t;
}

void thread_free(struct thread *t) {
	thread_pool_entry_t *block;

	assert(t != NULL);

	// TODO may be this is not the best way... -- Eldar
	block = member_cast_out(t, thread_pool_entry_t, thread);
	memset(block, 0xa5, sizeof(*block));

	pool_free(&thread_pool, block);
}
{'fraction_non_alphanumeric': 0.13342830009496676, 'fraction_numerical': 0.009971509971509971, 'mean_word_length': 4.9352112676056334, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, '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': '5814609', 'n_tokens_mistral': 839, 'n_tokens_neox': 788, 'n_words': 170}