IPC now uses a buffer in the task structure

This commit is contained in:
pjht 2019-06-17 08:14:45 -05:00
parent c4d39011cd
commit c295d56ae8
2 changed files with 20 additions and 8 deletions

View File

@ -109,21 +109,22 @@ void tasking_send_msg(uint32_t pid,void* msg,uint32_t size) {
for (Task* task=headTask;task!=NULL;task=task->next) {
if (task->pid==pid) {
uint32_t cr3;
asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(cr3)::"%eax");
void* phys_addr=virt_to_phys(msg);
load_address_space(task->cr3);
uint32_t page=find_free_pages((size/4096)+1);
map_pages((void*)(page<<12),phys_addr,(size/4096)+1,1,0);
if (task->msg_store==NULL) {
task->msg_store=malloc(sizeof(void*)*256);
task->sender_store=malloc(sizeof(uint32_t)*256);
}
task->msg_store[task->wr]=(void*)(page<<12);
task->sender_store[task->wr]=currentTask->pid;
load_address_space(cr3);
task->wr++;
if (task->wr==16) {
task->wr=0;
}
if (task->wr==task->rd) {
task->wr--;
if (task->wr==255) {
task->wr=15;
}
}
break;
}
@ -136,8 +137,14 @@ void* tasking_get_msg(uint32_t* sender) {
}
if (currentTask->msg_store[currentTask->rd]==NULL) {
currentTask->rd++;
if (currentTask->rd==16) {
currentTask->rd=0;
}
if (currentTask->msg_store[currentTask->rd]==NULL) {
currentTask->rd--;
if (currentTask->rd==255) {
currentTask->rd=15;
}
return NULL;
}
}
@ -146,8 +153,14 @@ void* tasking_get_msg(uint32_t* sender) {
currentTask->msg_store[currentTask->rd]=NULL;
currentTask->sender_store[currentTask->rd]=0;
currentTask->rd++;
if (currentTask->rd==16) {
currentTask->rd=0;
}
if (currentTask->rd>currentTask->wr) {
currentTask->rd=currentTask->wr-1;
if (currentTask->rd==255) {
currentTask->rd=15;
}
}
return data;
}

View File

@ -12,9 +12,8 @@ typedef struct Task {
char priv;
int errno;
uint32_t pid;
char** msg_store;
uint32_t* sender_store;
uint32_t msg_indx;
char* msg_store[16];
uint32_t sender_store[16];
uint8_t rd;
uint8_t wr;
struct Task* next;