<commit_before>/**
 * @file
 * @brief TODO
 *
 * @date 28.03.11
 * @author <NAME>
 * @author <NAME>
 */

#ifndef KERNEL_THREAD_STATE_IMPL_H_
#define KERNEL_THREAD_STATE_IMPL_H_

#include <assert.h>

// TODO don't like this include. -- Eldar
#include "types.h"

#define __THREAD_STATE_INIT       0x0

#define __THREAD_STATE_SLEEPING  (0x1 << 0)
#define __THREAD_STATE_SUSPENDED (0x1 << 1)
#define __THREAD_STATE_EXITED    (0x1 << 2)
#define __THREAD_STATE_DETACHED  (0x1 << 3)

static inline __thread_state_t thread_state_init(void) {
	return __THREAD_STATE_INIT;
}

static inline bool thread_state_sleeping(__thread_state_t state) {
	return state & __THREAD_STATE_SLEEPING;
}
static inline bool thread_state_suspended(__thread_state_t state) {
	return state & __THREAD_STATE_SUSPENDED;
}
static inline bool thread_state_exited(__thread_state_t state) {
	return state & __THREAD_STATE_EXITED;
}
static inline bool thread_state_detached(__thread_state_t state) {
	return state & __THREAD_STATE_DETACHED;
}
static inline bool thread_state_blocked(__thread_state_t state) {
	return thread_state_sleeping(state) || thread_state_suspended(state);
}
static inline bool thread_state_running(__thread_state_t state) {
	return !thread_state_blocked(state) && !thread_state_exited(state);
}
static inline bool thread_state_dead(__thread_state_t state) {
	return thread_state_detached(state) && thread_state_exited(state);
}

static inline __thread_state_t thread_state_do_sleep(__thread_state_t state) {
	assert(thread_state_running(state));
	return state | __THREAD_STATE_SLEEPING;
}
static inline __thread_state_t thread_state_do_wake(__thread_state_t state) {
	assert(!thread_state_exited(state) && thread_state_sleeping(state));
	return state & ~__THREAD_STATE_SLEEPING;
}
static inline __thread_state_t thread_state_do_suspend(__thread_state_t state) {
	assert(!thread_state_exited(state) && !thread_state_suspended(state));
	return state | __THREAD_STATE_SUSPENDED;
}
static inline __thread_state_t thread_state_do_resume(__thread_state_t state) {
	assert(!thread_state_exited(state) && thread_state_suspended(state));
	return state & ~__THREAD_STATE_SUSPENDED;
}
static inline __thread_state_t thread_state_do_exit(__thread_state_t state) {
	assert(thread_state_running(state));
	return state | __THREAD_STATE_EXITED;
}
static inline __thread_state_t thread_state_do_detach(__thread_state_t state) {
	assert(!thread_state_detached(state));
	return state | __THREAD_STATE_DETACHED;
}

#endif /* KERNEL_THREAD_STATE_IMPL_H_ */<commit_msg>Fix thread_state_init<commit_after>/**
 * @file
 * @brief TODO
 *
 * @date 28.03.11
 * @author <NAME>
 * @author <NAME>
 */

#ifndef KERNEL_THREAD_STATE_IMPL_H_
#define KERNEL_THREAD_STATE_IMPL_H_

#include <assert.h>

// TODO don't like this include. -- Eldar
#include "types.h"

#define __THREAD_STATE_INIT       __THREAD_STATE_SUSPENDED

#define __THREAD_STATE_SLEEPING  (0x1 << 0)
#define __THREAD_STATE_SUSPENDED (0x1 << 1)
#define __THREAD_STATE_EXITED    (0x1 << 2)
#define __THREAD_STATE_DETACHED  (0x1 << 3)

static inline __thread_state_t thread_state_init(void) {
	return __THREAD_STATE_INIT;
}

static inline bool thread_state_sleeping(__thread_state_t state) {
	return state & __THREAD_STATE_SLEEPING;
}
static inline bool thread_state_suspended(__thread_state_t state) {
	return state & __THREAD_STATE_SUSPENDED;
}
static inline bool thread_state_exited(__thread_state_t state) {
	return state & __THREAD_STATE_EXITED;
}
static inline bool thread_state_detached(__thread_state_t state) {
	return state & __THREAD_STATE_DETACHED;
}
static inline bool thread_state_blocked(__thread_state_t state) {
	return thread_state_sleeping(state) || thread_state_suspended(state);
}
static inline bool thread_state_running(__thread_state_t state) {
	return !thread_state_blocked(state) && !thread_state_exited(state);
}
static inline bool thread_state_dead(__thread_state_t state) {
	return thread_state_detached(state) && thread_state_exited(state);
}

static inline __thread_state_t thread_state_do_sleep(__thread_state_t state) {
	assert(thread_state_running(state));
	return state | __THREAD_STATE_SLEEPING;
}
static inline __thread_state_t thread_state_do_wake(__thread_state_t state) {
	assert(!thread_state_exited(state) && thread_state_sleeping(state));
	return state & ~__THREAD_STATE_SLEEPING;
}
static inline __thread_state_t thread_state_do_suspend(__thread_state_t state) {
	assert(!thread_state_exited(state) && !thread_state_suspended(state));
	return state | __THREAD_STATE_SUSPENDED;
}
static inline __thread_state_t thread_state_do_resume(__thread_state_t state) {
	assert(!thread_state_exited(state) && thread_state_suspended(state));
	return state & ~__THREAD_STATE_SUSPENDED;
}
static inline __thread_state_t thread_state_do_exit(__thread_state_t state) {
	assert(thread_state_suspended(state) && !thread_state_sleeping(state));
	return state | __THREAD_STATE_EXITED;
}
static inline __thread_state_t thread_state_do_detach(__thread_state_t state) {
	assert(!thread_state_detached(state));
	return state | __THREAD_STATE_DETACHED;
}

#endif /* KERNEL_THREAD_STATE_IMPL_H_ */
{'fraction_non_alphanumeric': 0.08521840873634945, 'fraction_numerical': 0.0074102964118564745, 'mean_word_length': 8.029929577464788, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 9, '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': '4127476', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1789, 'n_words': 330}