diff options
-rw-r--r-- | kernel/queue.c | 85 | ||||
-rw-r--r-- | kernel/queue.h | 27 | ||||
-rw-r--r-- | kernel/syscalls/queue.c | 14 |
3 files changed, 0 insertions, 126 deletions
diff --git a/kernel/queue.c b/kernel/queue.c deleted file mode 100644 index 43b2400..0000000 --- a/kernel/queue.c +++ /dev/null @@ -1,85 +0,0 @@ -#include <assert.h> -#include <kmalloc.h> -#include <queue.h> -#include <sched/scheduler.h> -#include <socket.h> -#include <stdio.h> - -int queue_create(u32 *id, process_t *p) { - struct event_queue *q = kcalloc(1, sizeof(struct event_queue)); - q->wait = 0; - q->p = p; - list_init(&q->events); - - struct list *list = ¤t_task->event_queue; - list_add(list, q, id); - return 1; -} - -struct event_queue *get_event_queue(u32 id) { - const struct list *list = ¤t_task->event_queue; - struct event_queue *q; - if (!list_get(list, id, (void **)&q)) { - return NULL; - } - return q; -} - -int queue_add(u32 queue_id, struct event *ev, u32 size) { - struct event_queue *q = get_event_queue(queue_id); - if (!q) { - return 0; - } - for (u32 i = 0; i < size; i++) { - // TODO: Should it be a copy or could it be kept in userland to - // improve performance? - struct event *new_ev = kmalloc(sizeof(struct event)); - memcpy(new_ev, ev, sizeof(struct event)); - list_add(&q->events, new_ev, NULL); - } - return 1; -} - -int queue_should_block(struct event_queue *q, int *is_empty) { - if (!q->wait) { - return 0; - } - *is_empty = 1; - for (int i = 0;; i++) { - struct event *ev; - if (!list_get(&q->events, i, (void **)&ev)) { - break; - } - *is_empty = 0; - if (EVENT_TYPE_FD == ev->type) { - vfs_fd_t *fd = get_vfs_fd(ev->internal_id, q->p); - if (!fd) { - kprintf("queue: Invalid fd given\n"); - continue; - } - if (fd->inode->_has_data) { - if (fd->inode->_has_data(fd->inode)) { - return 0; - } - } - } else if (EVENT_TYPE_TCP_SOCKET == ev->type) { - struct TcpConnection *con = tcp_get_connection(ev->internal_id, q->p); - assert(con); - if (!ringbuffer_isempty(&con->buffer)) { - return 0; - } - } - } - return 1; -} - -int queue_wait(u32 queue_id) { - struct event_queue *q = get_event_queue(queue_id); - if (!q) { - return 0; - } - q->wait = 1; - switch_task(); - q->wait = 0; - return 1; -} diff --git a/kernel/queue.h b/kernel/queue.h deleted file mode 100644 index 38cd992..0000000 --- a/kernel/queue.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef QUEUE_H -#define QUEUE_H -#include <lib/list.h> -#include <sched/scheduler.h> -#include <stddef.h> -#include <string.h> -#include <typedefs.h> - -#define EVENT_TYPE_FD 0 -#define EVENT_TYPE_TCP_SOCKET 1 - -struct event { - u8 type; // File descriptor | Socket - u32 internal_id; -}; - -struct event_queue { - struct list events; - int wait; - process_t *p; -}; - -int queue_create(u32 *id, process_t *p); -int queue_add(u32 queue_id, struct event *ev, u32 size); -int queue_wait(u32 queue_id); -int queue_should_block(struct event_queue *q, int *is_empty); -#endif diff --git a/kernel/syscalls/queue.c b/kernel/syscalls/queue.c deleted file mode 100644 index 8cd043b..0000000 --- a/kernel/syscalls/queue.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <queue.h> -#include <syscalls.h> - -int syscall_queue_create(u32 *id) { - return queue_create(id, current_task); -} - -int syscall_queue_add(u32 queue_id, struct event *ev, u32 size) { - return queue_add(queue_id, ev, size); -} - -int syscall_queue_wait(u32 queue_id) { - return queue_wait(queue_id); -} |