21 #ifndef COSA_IOBUFFER_HH 22 #define COSA_IOBUFFER_HH 35 template <u
int16_t SIZE>
37 static_assert(SIZE && !(SIZE & (SIZE - 1)),
"SIZE should be power of 2");
53 __attribute__((always_inline))
55 return (m_head == m_tail);
63 __attribute__((always_inline))
65 return (((m_head + 1) & MASK) == m_tail);
74 __attribute__((always_inline))
76 return ((SIZE + m_head - m_tail) & MASK);
85 __attribute__((always_inline))
87 return ((SIZE - m_head + m_tail - 1) & MASK);
131 __attribute__((always_inline))
139 operator const char*()
140 __attribute__((always_inline))
142 return (&m_buffer[m_tail + 1]);
146 static const uint16_t MASK = (SIZE - 1);
147 volatile uint16_t m_head;
148 volatile uint16_t m_tail;
152 template <u
int16_t SIZE>
156 uint16_t next = (m_head + 1) & MASK;
163 template <u
int16_t SIZE>
168 uint16_t next = (m_tail + 1) & MASK;
169 return (m_buffer[next] & 0xff);
172 template <u
int16_t SIZE>
176 uint16_t tail = m_tail;
178 while (tail != m_head) {
180 tail = (tail + 1) & MASK;
181 if (
UNLIKELY(m_buffer[tail] == c))
return (res);
186 template <u
int16_t SIZE>
191 uint16_t next = (m_tail + 1) & MASK;
193 return (m_buffer[next] & 0xff);
196 template <u
int16_t SIZE>
200 while (m_head != m_tail)
yield();
virtual int putchar(char c)
#define static_assert(condition, message)