-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b01a4a3
commit 208c657
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |