<commit_before>/**
 * \file
 * \brief Scheduler class implementation
 *
 * \author Copyright (C) 2014 <NAME> http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * \date 2014-07-30
 */

#include "distortos/scheduler/Scheduler.hpp"

#include "distortos/scheduler/ThreadControlBlock.hpp"

#include "distortos/architecture.hpp"

namespace distortos
{

namespace scheduler
{

/*---------------------------------------------------------------------------------------------------------------------+
| public functions
+---------------------------------------------------------------------------------------------------------------------*/

Scheduler::Scheduler()
{

}

void Scheduler::add(ThreadControlBlock &thread_control_block)
{
	threadControlBlockList_.emplace_back(thread_control_block);
}

void Scheduler::start()
{
	currentThreadControlBlock_ = threadControlBlockList_.begin();

	architecture::startScheduling();
}

void * Scheduler::switchContext(void *stack_pointer)
{
	getCurrentThreadControlBlock().getStack().setStackPointer(stack_pointer);

	const auto previous_thread_control_block = *currentThreadControlBlock_;
	threadControlBlockList_.erase(currentThreadControlBlock_);
	threadControlBlockList_.emplace_back(previous_thread_control_block);

	currentThreadControlBlock_ = threadControlBlockList_.begin();

	return (*currentThreadControlBlock_).get().getStack().getStackPointer();
}

}	// namespace scheduler

}	// namespace distortos<commit_msg>scheduler: implement round-robin scheduling with std::list::splice() instead of doing erase() + emplace_back()<commit_after>/**
 * \file
 * \brief Scheduler class implementation
 *
 * \author Copyright (C) 2014 <NAME> http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * \date 2014-07-30
 */

#include "distortos/scheduler/Scheduler.hpp"

#include "distortos/scheduler/ThreadControlBlock.hpp"

#include "distortos/architecture.hpp"

namespace distortos
{

namespace scheduler
{

/*---------------------------------------------------------------------------------------------------------------------+
| public functions
+---------------------------------------------------------------------------------------------------------------------*/

Scheduler::Scheduler()
{

}

void Scheduler::add(ThreadControlBlock &thread_control_block)
{
	threadControlBlockList_.emplace_back(thread_control_block);
}

void Scheduler::start()
{
	currentThreadControlBlock_ = threadControlBlockList_.begin();

	architecture::startScheduling();
}

void * Scheduler::switchContext(void *stack_pointer)
{
	getCurrentThreadControlBlock().getStack().setStackPointer(stack_pointer);

	// move current thread to the end of same-priority group to implement round-robin scheduling
	threadControlBlockList_.splice(threadControlBlockList_.end(), threadControlBlockList_, currentThreadControlBlock_);
	currentThreadControlBlock_ = threadControlBlockList_.begin();

	return getCurrentThreadControlBlock().getStack().getStackPointer();
}

}	// namespace scheduler

}	// namespace distortos
{'fraction_non_alphanumeric': 0.23330442324371206, 'fraction_numerical': 0.009251228678808905, 'mean_word_length': 2.7855579868708973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4894397', 'n_tokens_mistral': 939, 'n_tokens_neox': 891, 'n_words': 201}