This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
-
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.
Aggiunti semafori con implementazione generica
Aggiornato uso di semafori per handler uMPS #20 Aggiornato uso di semafori per Syscall 4-5 #19 Aggiunte funzioni P e V per semafori in utilities Aggiunta scheduler_RemoveProcess per rimuovere un preciso pcb dallo scheduler #12
- Loading branch information
Showing
8 changed files
with
101 additions
and
29 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
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
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,29 @@ | ||
#ifndef _UTIL_SEMAPHORE_ | ||
#define _UTIL_SEMAPHORE_ | ||
|
||
#include <pcb/pcb.h> | ||
|
||
/** | ||
* @brief Decrementa il valore del semaforo, se diventa < 0, allora il processo indicato viene sospeso; | ||
* cioè rimosso dalla ready queue dello scheduler e posto in attesa sulla coda del semaforo specificato | ||
* @PreCondition semkey != NULL | ||
* | ||
* @param semkey | ||
* @param p | ||
* @return int | ||
* FALSE se è stato sospeso correttamente | ||
* TRUE se p == NULL oppure se non è stato possibile allocare un semd per il processo specificato | ||
*/ | ||
int semaphore_P( int *semkey, pcb_t * p ); | ||
|
||
/** | ||
* @brief Incrementa il valore del semaforo, se il suo valore diventa <= 0, allora il primo processo in coda | ||
* associato al semaforo specificato è risvegliato; cioè aggiunto alla ready queue | ||
* @PreCondition semkey != NULL | ||
* | ||
* @param semkey | ||
* @return pcb_t* il puntatore al pcb risvegliato | ||
*/ | ||
pcb_t *semaphore_V( int *semkey ); | ||
|
||
#endif |
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
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
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
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
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,26 @@ | ||
#include <utilities/semaphore.h> | ||
#include <scheduler/scheduler.h> | ||
#include <asl/asl.h> | ||
#include <pcb/pcb.h> | ||
|
||
int semaphore_P( int *semkey, pcb_t * p ) { | ||
int b_error = FALSE; | ||
if( p == NULL ) | ||
return !b_error; | ||
|
||
if( --(*semkey) < 0 ) { | ||
scheduler_RemoveProcess( p ); | ||
b_error = insertBlocked( semkey, p ); | ||
} | ||
return b_error; | ||
} | ||
|
||
pcb_t *semaphore_V( int *semkey ) { | ||
pcb_t *p = NULL; | ||
if( ++(*semkey) <= 0 ) { | ||
p = removeBlocked( semkey ); | ||
if( p != NULL ) | ||
scheduler_AddProcess( p ); | ||
} | ||
return p; | ||
} |