Skip to content

Commit

Permalink
feat(kernel): add pcb unit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez committed May 11, 2022
1 parent b01a4a3 commit 208c657
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
27 changes: 27 additions & 0 deletions kernel/inc/scheduling/pcb_state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file pcb_state.h
* @author Tomás Sánchez <[email protected]>
* @brief
* @version 0.1
* @date 05-10-2022
*
* @copyright Copyright (c) 2022
*
*/

#pragma once

/**
* @brief A Process State.
*
*/
typedef enum ProcessState
{
NEW,
READY,
EXECUTING,
SUSPENDED_READY,
BLOCKED,
SUSPENDED_BLOCKED,
TERMINATED
} pcb_state_t;
43 changes: 43 additions & 0 deletions kernel/inc/scheduling/pcb_unit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @file pcb_unit.h
* @author Tomás Sánchez <[email protected]>
* @brief
* @version 0.1
* @date 05-10-2022
*
* @copyright Copyright (c) 2022
*
*/

#pragma once

#include "pcb.h"
#include "pcb_state.h"

/**
* @brief A PCB Scheduler's Unit.
*
*/
typedef struct PcbUnit
{
// The PCB Itself
pcb_t *_pcb;
// The Scheduler data
pcb_state_t state;
} pcb_unit_t;

/**
* @brief Creates a new PCB Unit
*
* @param pcb reference which contains the data
* @return a unit to be scheduled
*/
pcb_unit_t *
new_pcb_unit(pcb_t *pcb);

/**
* @brief Deallocates Memory used by a PCB_UNIT
*
* @param pcb_unit to be deleted
*/
void pcb_unit_destroy(void *pcb_unit);
32 changes: 32 additions & 0 deletions kernel/src/scheduling/pcb_unit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file pcb_unit.c
* @author Tomás Sánchez <[email protected]>
* @brief
* @version 0.1
* @date 05-10-2022
*
* @copyright Copyright (c) 2022
*
*/

#include <stdlib.h>
#include "pcb_unit.h"
#include "pcb_state.h"

pcb_unit_t *
new_pcb_unit(pcb_t *pcb)
{
pcb_unit_t *process = malloc(sizeof(pcb_unit_t));
process->_pcb = pcb;
process->state = NEW;
}

void pcb_unit_destroy(void *pcb_unit)
{
if (pcb_unit)
{
pcb_unit_t *process = pcb_unit;
pcb_destroy(process->_pcb);
free(process);
}
}

0 comments on commit 208c657

Please sign in to comment.