<commit_before>/**
 * @file
 * @brief Multi-thread sleep
 *
 * @date 05.07.11
 * @author <NAME>
 * @author <NAME>
 */

#include <types.h>
#include <time.h>
#include <kernel/timer.h>
#include <kernel/thread/sched.h>
#include <kernel/thread/event.h>

static void restore_thread(sys_timer_t *timer, void *param) {
	sched_wake((struct event *) param);
}

/* system library function */
int usleep(useconds_t usec) {
	struct event wait_event;
	sys_timer_t tmr; /* we allocate timer structure on the stack */

	event_init(&wait_event, NULL);

	sched_lock();

	if (timer_init(&tmr, usec, &restore_thread, &wait_event)) {
		return 1;
	}

	sched_sleep_locked(&wait_event);

	timer_close(&tmr);

	sched_unlock();
	return 0;
}

int sleep(unsigned int seconds) {
	return usleep(seconds * 1000);
}
<commit_msg>Fix the same error in usleep<commit_after>/**
 * @file
 * @brief Multi-thread sleep
 *
 * @date 05.07.11
 * @author <NAME>
 * @author <NAME>
 */

#include <errno.h>
#include <types.h>
#include <time.h>

#include <kernel/timer.h>
#include <kernel/thread/sched.h>
#include <kernel/thread/event.h>

static void restore_thread(sys_timer_t *timer, void *param) {
	sched_wake((struct event *) param);
}

/* system library function */
int usleep(useconds_t usec) {
	int ret = 0;
	struct event wait_event;
	sys_timer_t tmr; /* we allocate timer structure on the stack */

	event_init(&wait_event, NULL);

	sched_lock();
	{
		if (0 != timer_init(&tmr, usec, &restore_thread, &wait_event)) {
			ret = -EBUSY;
			goto out_unlock;
		}

		sched_sleep_locked(&wait_event);

		timer_close(&tmr);
	}
	out_unlock: sched_unlock();

	return ret;
}

int sleep(unsigned int seconds) {
	return usleep(seconds * 1000);
}

{'fraction_non_alphanumeric': 0.1487603305785124, 'fraction_numerical': 0.014167650531286895, 'mean_word_length': 4.380952380952381, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '6056465', 'n_tokens_mistral': 663, 'n_tokens_neox': 624, 'n_words': 154}