Skip to content

Commit

Permalink
fix: minor fixes in swap controller exit
Browse files Browse the repository at this point in the history
Co-authored-by: Tomas Sanchez <tosanchez@frba.utn.edu.ar>
Co-authored-by: Franco Daniel Parente <fparente14@frba.utn.edu.ar>
  • Loading branch information
3 people committed Jul 22, 2022
1 parent aa749fa commit b69b1f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 7 additions & 0 deletions kernel/inc/client/swap_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ ssize_t swap_controller_request_pcb(uint32_t pid);
* @return a PCB object
*/
void *swap_controller_receive_pcb(void);

/**
* @brief Sends PID and page_table to memory
*
*/
ssize_t swap_controller_exit(pcb_t *pcb)

13 changes: 7 additions & 6 deletions kernel/src/client/swap_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ swap_controller_receive_pcb(void)
return recovered_pcb;
}

void *
swap_controller_exit(opcode_t opcode, pcb_t *pcb)
ssize_t swap_controller_exit(pcb_t *pcb)
{
void *stream = NULL;
void *conexion = NULL;

opcode_t pcb_terminated = PROCESS_TERMINATED;
uint32_t pid = pcb->id;
uint32_t page_table = pcb->page_table;
uint32_t size = sizeof(pid) + sizeof(page_table);

stream = malloc(sizeof(pid + page_table));
memcpy(stream, &pid, sizeof(stream));
memcpy(stream, &page_table, sizeof(stream));
stream = malloc(size);
uint32_t offset = 0;
memcpy(stream, &pid, sizeof(pid));
offset += sizeof(pid);
memcpy(stream + offset, &page_table, sizeof(page_table));

ssize_t ret = conexion_enviar_stream(g_kernel.conexion_memory, pcb_terminated, stream, sizeof(stream));
free(stream);
Expand Down
6 changes: 2 additions & 4 deletions kernel/src/scheduling/sts.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "log.h"
#include "cfg.h"
#include "mts.h"
#include "swap_controller.h"

void execute(kernel_t *kernel, pcb_t *pcb);
void terminate(kernel_t *kernel, pcb_t *pcb);
Expand Down Expand Up @@ -123,12 +124,9 @@ void execute(kernel_t *kernel, pcb_t *pcb)
void terminate(kernel_t *kernel, pcb_t *pcb)
{
SIGNAL(kernel->scheduler.dom);
swap_controller_exit(pcb);
pcb_destroy(pcb);
pcb = NULL;

opcode_t pcb_terminated = PROCESS_TERMINATED;
ssize_t bytes_sent = -1;
bytes_sent = connection_send_value(kernel->conexion_memory, &pcb_terminated, sizeof(pcb_terminated));
}

void block(scheduler_t *scheduler, pcb_t *pcb, uint32_t io_time)
Expand Down

0 comments on commit b69b1f3

Please sign in to comment.