1

rename Iterator to iterator

This commit is contained in:
2022-07-23 21:38:16 +02:00
parent c95361552a
commit 94cc244868
5 changed files with 29 additions and 29 deletions

View File

@ -35,7 +35,7 @@ constexpr const bool INSANE_TRACE = false;
* Parameter: * * Parameter: *
* next Thread der die CPU erhalten soll. * * next Thread der die CPU erhalten soll. *
*****************************************************************************/ *****************************************************************************/
void Scheduler::start(bse::vector<bse::unique_ptr<Thread>>::Iterator next) { void Scheduler::start(bse::vector<bse::unique_ptr<Thread>>::iterator next) {
active = next; active = next;
if (active >= ready_queue.end()) { if (active >= ready_queue.end()) {
active = ready_queue.begin(); active = ready_queue.begin();
@ -47,7 +47,7 @@ void Scheduler::start(bse::vector<bse::unique_ptr<Thread>>::Iterator next) {
(*active)->start(); // First dereference the Iterator, then the unique_ptr to get Thread (*active)->start(); // First dereference the Iterator, then the unique_ptr to get Thread
} }
void Scheduler::switch_to(Thread* prev_raw, bse::vector<bse::unique_ptr<Thread>>::Iterator next) { void Scheduler::switch_to(Thread* prev_raw, bse::vector<bse::unique_ptr<Thread>>::iterator next) {
active = next; active = next;
if (active >= ready_queue.end()) { if (active >= ready_queue.end()) {
active = ready_queue.begin(); active = ready_queue.begin();
@ -137,7 +137,7 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
unsigned int prev_tid = (*active)->tid; unsigned int prev_tid = (*active)->tid;
// Block queue, can always kill // Block queue, can always kill
for (bse::vector<bse::unique_ptr<Thread>>::Iterator it = block_queue.begin(); it != block_queue.end(); ++it) { for (bse::vector<bse::unique_ptr<Thread>>::iterator it = block_queue.begin(); it != block_queue.end(); ++it) {
if ((*it)->tid == tid) { if ((*it)->tid == tid) {
// Found thread to kill // Found thread to kill
@ -163,7 +163,7 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
return; return;
} }
for (bse::vector<bse::unique_ptr<Thread>>::Iterator it = ready_queue.begin(); it != ready_queue.end(); ++it) { for (bse::vector<bse::unique_ptr<Thread>>::iterator it = ready_queue.begin(); it != ready_queue.end(); ++it) {
if ((*it)->tid == tid) { if ((*it)->tid == tid) {
// Found thread to kill // Found thread to kill
@ -318,7 +318,7 @@ void Scheduler::deblock(unsigned int tid) {
cpu.disable_int(); cpu.disable_int();
for (bse::vector<bse::unique_ptr<Thread>>::Iterator it = block_queue.begin(); it != block_queue.end(); ++it) { for (bse::vector<bse::unique_ptr<Thread>>::iterator it = block_queue.begin(); it != block_queue.end(); ++it) {
if ((*it)->tid == tid) { if ((*it)->tid == tid) {
// Found thread with correct tid // Found thread with correct tid

View File

@ -28,15 +28,15 @@ private:
// NOTE: It makes sense to keep track of the active thread through this as it makes handling the // NOTE: It makes sense to keep track of the active thread through this as it makes handling the
// unique_ptr easier and reduces the copying in the vector when cycling through the threads // unique_ptr easier and reduces the copying in the vector when cycling through the threads
bse::vector<bse::unique_ptr<Thread>>::Iterator active = nullptr; bse::vector<bse::unique_ptr<Thread>>::iterator active = nullptr;
// Scheduler wird evt. von einer Unterbrechung vom Zeitgeber gerufen, // Scheduler wird evt. von einer Unterbrechung vom Zeitgeber gerufen,
// bevor er initialisiert wurde // bevor er initialisiert wurde
unsigned int idle_tid = 0U; unsigned int idle_tid = 0U;
// Roughly the old dispatcher functionality // Roughly the old dispatcher functionality
void start(bse::vector<bse::unique_ptr<Thread>>::Iterator next); // Start next without prev void start(bse::vector<bse::unique_ptr<Thread>>::iterator next); // Start next without prev
void switch_to(Thread* prev_raw, bse::vector<bse::unique_ptr<Thread>>::Iterator next); // Switch from prev to next void switch_to(Thread* prev_raw, bse::vector<bse::unique_ptr<Thread>>::iterator next); // Switch from prev to next
// Kann nur vom Idle-Thread aufgerufen werden (erster Thread der vom Scheduler gestartet wird) // Kann nur vom Idle-Thread aufgerufen werden (erster Thread der vom Scheduler gestartet wird)
void enable_preemption(unsigned int tid) { idle_tid = tid; } void enable_preemption(unsigned int tid) { idle_tid = tid; }

View File

@ -8,7 +8,7 @@ void KeyEventManager::subscribe(KeyEventListener& sub) {
void KeyEventManager::unsubscribe(KeyEventListener& unsub) { void KeyEventManager::unsubscribe(KeyEventListener& unsub) {
log.debug() << "Unsubscribe, Thread ID: " << dec << unsub.tid << endl; log.debug() << "Unsubscribe, Thread ID: " << dec << unsub.tid << endl;
for (bse::vector<KeyEventListener*>::Iterator it = listeners.begin(); it != listeners.end(); ++it) { for (bse::vector<KeyEventListener*>::iterator it = listeners.begin(); it != listeners.end(); ++it) {
if ((*it)->tid == unsub.tid) { if ((*it)->tid == unsub.tid) {
this->listeners.erase(it); this->listeners.erase(it);
return; return;

View File

@ -10,14 +10,14 @@ namespace bse {
template<typename T, const std::size_t N> template<typename T, const std::size_t N>
class array { class array {
public: public:
using Iterator = ContinuousIterator<T>; using iterator = ContinuousIterator<T>;
private: private:
T buf[N]; T buf[N];
public: public:
Iterator begin() { return Iterator(&buf[0]); } iterator begin() { return iterator(&buf[0]); }
Iterator end() { return Iterator(&buf[N]); } iterator end() { return iterator(&buf[N]); }
T& operator[](std::size_t i) { T& operator[](std::size_t i) {
return this->buf[i]; return this->buf[i];

View File

@ -5,8 +5,8 @@
// Also I wanted to template the Queue (for the scheduler) but with this I can just replace the Queue and use the // Also I wanted to template the Queue (for the scheduler) but with this I can just replace the Queue and use the
// ArrayList instead // ArrayList instead
#include "Iterator.h" #include "user/lib/Iterator.h"
#include "Logger.h" #include "user/lib/Logger.h"
#include <utility> #include <utility>
// https://en.cppreference.com/w/cpp/container/vector // https://en.cppreference.com/w/cpp/container/vector
@ -15,7 +15,7 @@ namespace bse {
template<typename T> template<typename T>
class vector { class vector {
public: public:
using Iterator = ContinuousIterator<T>; using iterator = ContinuousIterator<T>;
private: private:
static constexpr const std::size_t default_cap = 10; // Arbitrary but very small because this isn't a real OS :( static constexpr const std::size_t default_cap = 10; // Arbitrary but very small because this isn't a real OS :(
@ -106,29 +106,29 @@ namespace bse {
} }
// Iterator // Iterator
Iterator begin() { iterator begin() {
if (buf == nullptr) { if (buf == nullptr) {
init(); init();
} }
return Iterator(&buf[0]); return iterator(&buf[0]);
} }
Iterator begin() const { iterator begin() const {
if (buf == nullptr) { if (buf == nullptr) {
init(); init();
} }
return Iterator(&buf[0]); return iterator(&buf[0]);
} }
Iterator end() { iterator end() {
if (buf == nullptr) { if (buf == nullptr) {
init(); init();
} }
return Iterator(&buf[size()]); return iterator(&buf[size()]);
} }
Iterator end() const { iterator end() const {
if (buf == nullptr) { if (buf == nullptr) {
init(); init();
} }
return Iterator(&buf[size()]); return iterator(&buf[size()]);
} }
// Add elements // Add elements
@ -155,33 +155,33 @@ namespace bse {
// https://en.cppreference.com/w/cpp/container/vector/insert // https://en.cppreference.com/w/cpp/container/vector/insert
// The element will be inserted before the pos iterator, pos can be the end() iterator // The element will be inserted before the pos iterator, pos can be the end() iterator
Iterator insert(Iterator pos, const T& copy) { iterator insert(iterator pos, const T& copy) {
std::size_t idx = distance(begin(), pos); // begin() does init if necessary std::size_t idx = distance(begin(), pos); // begin() does init if necessary
copy_right(idx); // nothing will be done if pos == end() copy_right(idx); // nothing will be done if pos == end()
buf[idx] = copy; buf[idx] = copy;
++buf_pos; ++buf_pos;
min_expand(); min_expand();
return Iterator(&buf[idx]); return iterator(&buf[idx]);
} }
Iterator insert(Iterator pos, T&& move) { iterator insert(iterator pos, T&& move) {
std::size_t idx = distance(begin(), pos); // begin() does init if necessary std::size_t idx = distance(begin(), pos); // begin() does init if necessary
copy_right(idx); copy_right(idx);
buf[idx] = std::move(move); buf[idx] = std::move(move);
++buf_pos; ++buf_pos;
min_expand(); min_expand();
return Iterator(&buf[idx]); return iterator(&buf[idx]);
} }
// Remove elements // Remove elements
// https://en.cppreference.com/w/cpp/container/vector/erase // https://en.cppreference.com/w/cpp/container/vector/erase
// Returns the iterator after the removed element, pos can't be end() iterator // Returns the iterator after the removed element, pos can't be end() iterator
Iterator erase(Iterator pos) { iterator erase(iterator pos) {
std::size_t idx = distance(begin(), pos); std::size_t idx = distance(begin(), pos);
copy_left(idx); copy_left(idx);
--buf_pos; --buf_pos;
// shrink(); // shrink();
return Iterator(&buf[idx]); return iterator(&buf[idx]);
} }
// Access // Access