Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

Commit

Permalink
Fix semafori e gestione sospensione processo #12
Browse files Browse the repository at this point in the history
  • Loading branch information
jjak0b committed May 11, 2020
1 parent 1d42b6f commit 8dc5f05
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
24 changes: 13 additions & 11 deletions src/handler/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,23 @@ void Sys6_DoIO( word command, word *devregAddr, int subdevice ) {
int *semKey = device_GetSem( devLine, devNo, subdevice );
pcb_t *pid = scheduler_GetRunningProcess();
// un semaforo di un device è sempre almeno inizializzato a 0, e quindi è sempre sospeso
int b_error = semaphore_P( semKey, pid );
if( b_error ) {
scheduler_StateToTerminate( pid, FALSE );
}

if( devLine == IL_TERMINAL ) {
if( subdevice ) {
devreg->term.transm_command = command;
if( *semKey >= 0 ){
if( devLine == IL_TERMINAL ) {
if( subdevice ) {
devreg->term.transm_command = command;
}
else {
devreg->term.recv_command = command;
}
}
else {
devreg->term.recv_command = command;
devreg->dtp.command = command;
}
}
else {
devreg->dtp.command = command;

int b_error = semaphore_P( semKey, pid );
if( b_error ) {
scheduler_StateToTerminate( pid, FALSE );
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/scheduler/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,10 @@ int scheduler_StateToWaiting( int* semKey ) {
if( p == NULL ) {
return -1;
}

scheduler_StateToReady();
scheduler_RemoveProcess( p );
int b_result = insertBlocked( semKey, p );
if( !b_result ) {
scheduler->running_p = NULL;
scheduler->b_force_switch = TRUE;
return 0;
}
else {
return 1;
}
return b_result;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/utilities/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ int semaphore_P( int *semkey, pcb_t * p ) {
return !b_error;

if( --(*semkey) < 0 ) {
scheduler_RemoveProcess( p );
b_error = insertBlocked( semkey, p );
if( p == scheduler_GetRunningProcess() ){
b_error = scheduler_StateToWaiting( semkey );
}
else {
scheduler_RemoveProcess( p );
b_error = insertBlocked( semkey, p );
}
}
return b_error;
}
Expand Down

0 comments on commit 8dc5f05

Please sign in to comment.