ladybird/AK/CircularQueue.h
Andreas Kling fe237ee215 Lots of hacking:
- Turn Keyboard into a CharacterDevice (85,1) at /dev/keyboard.
- Implement MM::unmapRegionsForTask() and MM::unmapRegion()
- Save SS correctly on interrupt.
- Add a simple Spawn syscall for launching another process.
- Move a bunch of IO syscall debug output behind DEBUG_IO.
- Have ASSERT do a "cli" immediately when failing.
  This makes the output look proper every time.
- Implement a bunch of syscalls in LibC.
- Add a simple shell ("sh"). All it can do now is read a line
  of text from /dev/keyboard and then try launching the specified
  executable by calling spawn().

There are definitely bugs in here, but we're moving on forward.
2018-10-23 10:12:50 +02:00

56 lines
1.1 KiB
C++

#pragma once
#include "Assertions.h"
#include "Types.h"
namespace AK {
template<typename T, size_t capacity>
class CircularQueue {
public:
CircularQueue()
{
for (size_t i = 0; i < capacity; ++i)
m_elements[i] = T();
}
bool isEmpty() const { return !m_size; }
size_t size() const { return m_size; }
void dump() const
{
kprintf("CircularQueue<%zu>:\n", capacity);
kprintf(" size: %zu\n", m_size);
for (size_t i = 0; i < capacity; ++i) {
kprintf(" [%zu] %d %c\n", i, m_elements[i], i == m_head ? '*' : ' ');
}
}
void enqueue(const T& t)
{
m_elements[(m_head + m_size) % capacity] = t;
if (m_size == capacity)
m_head = (m_head + 1) % capacity;
else
++m_size;
}
T dequeue()
{
ASSERT(!isEmpty());
T value = m_elements[m_head];
m_head = (m_head + 1) % capacity;
--m_size;
return value;
}
private:
T m_elements[capacity];
size_t m_size { 0 };
size_t m_head { 0 };
};
}
using AK::CircularQueue;