diff options
author | Marvin Borner | 2020-08-22 19:44:49 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-22 19:44:49 +0200 |
commit | 8bb7b5cceaaf96a5dd6321d35aae28748896d87b (patch) | |
tree | 9a4103fb1da636fdf0c5ec8f04425c0c388f527d /kernel/features/proc.c | |
parent | 424dc57424ee17de77d689443f95d2e1bed72f4a (diff) |
Added *very* basic polling ipc
Diffstat (limited to 'kernel/features/proc.c')
-rw-r--r-- | kernel/features/proc.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/kernel/features/proc.c b/kernel/features/proc.c index b968032..4d4a9f3 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -99,6 +99,30 @@ struct proc *proc_current() return NULL; } +void proc_send(struct proc *src, struct proc *dest, enum message_type type, void *data) +{ + assert(src && dest); + struct proc_message *msg = malloc(sizeof(*msg)); + msg->src = src; + msg->dest = dest; + msg->msg = malloc(sizeof(struct message)); + msg->msg->src = src->pid; + msg->msg->type = type; + msg->msg->data = data; + list_add(dest->messages, msg); +} + +struct proc_message *proc_receive(struct proc *proc) +{ + if (proc->messages && proc->messages->head) { + struct proc_message *msg = proc->messages->head->data; + list_remove(proc->messages, proc->messages->head); + return msg; + } else { + return NULL; + } +} + void proc_resolve(struct proc *proc) { proc->state = PROC_RESOLVED; @@ -107,6 +131,17 @@ void proc_resolve(struct proc *proc) hlt(); } +struct proc *proc_from_pid(u32 pid) +{ + struct node *iterator = proc_list->head; + do { + if (((struct proc *)iterator->data)->pid == pid) { + return iterator->data; + } + } while ((iterator = iterator->next) != NULL); + return NULL; +} + void proc_exit(struct proc *proc, int status) { assert(proc); @@ -130,6 +165,7 @@ struct proc *proc_make() struct proc *proc = malloc(sizeof(*proc)); proc->pid = pid++; proc->events = list_new(); + proc->messages = list_new(); proc->state = PROC_DEFAULT; if (current) |