Further queue improvements
This commit is contained in:
parent
e5da45df2f
commit
b5f5a40fbc
@ -50,3 +50,11 @@
|
|||||||
#define _QUEUE_PEEK(queue, entry, type) \
|
#define _QUEUE_PEEK(queue, entry, type) \
|
||||||
(queue.first)
|
(queue.first)
|
||||||
#define queue_peek(...) _QUEUE_PEEK(__VA_ARGS__)
|
#define queue_peek(...) _QUEUE_PEEK(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define _QUEUE_POP(queue, entry, type) \
|
||||||
|
__extension__({ \
|
||||||
|
type *_ret = _QUEUE_PEEK(queue, entry, type); \
|
||||||
|
_QUEUE_DROP(queue, entry, type); \
|
||||||
|
_ret; \
|
||||||
|
})
|
||||||
|
#define queue_pop(...) _QUEUE_POP(__VA_ARGS__)
|
||||||
|
@ -58,3 +58,18 @@ TEST(empty_reports_nonempty_queue_not_empty)
|
|||||||
queue_add(TestQ, &item1);
|
queue_add(TestQ, &item1);
|
||||||
ASSERT_EQ_INT(!!queue_empty(TestQ), 0);
|
ASSERT_EQ_INT(!!queue_empty(TestQ), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(pop_returns_queued_item)
|
||||||
|
{
|
||||||
|
queue_add(TestQ, &item1);
|
||||||
|
struct item *i = queue_pop(TestQ);
|
||||||
|
ASSERT_EQ_INT(i->id, 1);
|
||||||
|
}
|
||||||
|
TEST(pop_removes_item_from_queue)
|
||||||
|
{
|
||||||
|
queue_add(TestQ, &item1);
|
||||||
|
queue_add(TestQ, &item2);
|
||||||
|
queue_pop(TestQ);
|
||||||
|
struct item *i = queue_peek(TestQ);
|
||||||
|
ASSERT_EQ_INT(i->id, 2);
|
||||||
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
|
|
||||||
#define READYQ readyQ, readyQ_next, struct thread
|
#define runQ readyQ, readyQ_next, struct thread
|
||||||
QUEUE_DECLARE(READYQ);
|
QUEUE_DECLARE(runQ);
|
||||||
|
|
||||||
void ready(struct thread *th);
|
void ready(struct thread *th);
|
||||||
struct thread *scheduler_next();
|
struct thread *scheduler_next();
|
||||||
|
@ -8,7 +8,7 @@ struct thread
|
|||||||
uintptr_t stack_ptr;
|
uintptr_t stack_ptr;
|
||||||
uint64_t tid;
|
uint64_t tid;
|
||||||
uint64_t state;
|
uint64_t state;
|
||||||
QUEUE_SPOT(READYQ);
|
QUEUE_SPOT(runQ);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,16 +2,14 @@
|
|||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
#include <thread.h>
|
#include <thread.h>
|
||||||
|
|
||||||
QUEUE_DEFINE(READYQ);
|
QUEUE_DEFINE(runQ);
|
||||||
|
|
||||||
void ready(struct thread *th)
|
void ready(struct thread *th)
|
||||||
{
|
{
|
||||||
queue_add(READYQ, th);
|
queue_add(runQ, th);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct thread *scheduler_next()
|
struct thread *scheduler_next()
|
||||||
{
|
{
|
||||||
struct thread *th = queue_peek(READYQ);
|
return queue_pop(runQ);
|
||||||
queue_drop(READYQ);
|
|
||||||
return th;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user