Orion
Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)/* * This file contains all the functions related to message passing and * inter-process communication. */ #include <stdint.h> #include <stddef.h> #include <sys/ipc.h> #include "task.h" #include "../proc/proc.h" #include "../mem/mem.h" #include "../mem/heap.h" #include "../spinlock.h" extern TaskQueue readyQueue; /* Block until a message is received */ static uint8_t block_recv(Task *task, uint32_t from) { // Message *head, *prev; // /* Blocking for RECEIVE from any */ // if (!task->msgQueue) // return 0; // /* Block for RECEIVE from specific process */ // if (task->msgQueue->from != from && from != ANY) { // for (head = task->msgQueue; // head->from != from; // prev = head, head = head->next); // /* End of list */ // if (!head) return 0; // /* Move message to start of queue */ // if (head != task->msgQueue) { // prev->next = head->next; // head->next = task->msgQueue; // task->msgQueue = head; // } // } // // return 1; } /* Send a message */ Message * nb_send_msg(pid_t to, uint16_t type, MessageContent *msg) { // Message *item, *msgSearch; // Task *taskSearch; // // item = kmalloc(sizeof(Message)); // memcpy(&item->msg, msg, sizeof(MessageContent)); // item->from = current->tid; // item->type = type; // item->next = 0; // // /* Find target process */ // for (taskSearch = readyQueue; // taskSearch->tid != to && taskSearch; // taskSearch = taskSearch->next); // /* Add message to queue */ // if (taskSearch) { // acquire(&taskSearch->lock); // if (taskSearch->msgQueue) { // for (msgSearch = taskSearch->msgQueue; // msgSearch->next; // msgSearch = msgSearch->next); // msgSearch->next = item; // } else { // taskSearch->msgQueue = item; // } // release(&taskSearch->lock); // } // // if (taskSearch) // return item; // kfree(item); // return NULL; } /* Send a message and block until it is delivered */ Message * send_msg(pid_t to, uint16_t type, MessageContent *msg) { // Message *nb = nb_send_msg(to, type, msg); // if (!nb) return NULL; // block(block_send, (uint32_t) nb); // return nb; } /* Receive a message */ pid_t nb_recv_msg(Message *buf, pid_t from) { // Message *msg; // Task *taskSearch; // // acquire(¤t->lock); // msg = current->msgQueue; // if (msg && (msg->from == from || from == ANY)) { // current->msgQueue = msg->next; // memcpy(buf, msg, sizeof(Message)); // kfree(msg); // } // release(¤t->lock); // // if (msg && (buf->from == from || from == ANY)) { // /* Find sending process */ // for (taskSearch = readyQueue; // taskSearch->tid != buf->from && taskSearch; // taskSearch = taskSearch->next); // if (taskSearch) { // if (taskSearch->block.function == block_send // && taskSearch->block.condition == (uint32_t) msg) // taskSearch->block.function = NULL; // } // return buf->from; // } // return 0; } /* Block until a message is received */ pid_t recv_msg(Message *buf, pid_t from) { // pid_t nb; //check: // nb = nb_recv_msg(buf, from); // if (nb) return nb; // block(block_recv, from); // goto check; }