TD2 II.4 Call exit if there is no space avaible on Stack
Put Thread in sleep mode was a bad idea beause of synch (barrier for example)
This commit is contained in:
parent
4da093ca38
commit
3877e32b59
3 changed files with 22 additions and 10 deletions
|
@ -132,7 +132,7 @@ AddrSpace::AddrSpace (OpenFile * executable)
|
|||
pageTable[0].valid = FALSE; // Catch NULL dereference
|
||||
|
||||
#ifdef CHANGED
|
||||
int bitmapSize = UserStacksAreaSize / UserStackSize;
|
||||
int bitmapSize =( UserStacksAreaSize / UserStackSize)-1;
|
||||
DEBUG('x', "Initialise thread counter\n");
|
||||
threads = 1;
|
||||
|
||||
|
@ -325,20 +325,26 @@ AddrSpace::AllocateUserStack()
|
|||
/* If we don't have any free slot, we can wait for one to be
|
||||
* freed by DeAllocateUserstack
|
||||
*/
|
||||
while ((bit = memoryMap->Find()) == - 1){
|
||||
DEBUG('x', "Can't allocate User Stack Wainting...\n");
|
||||
semAllocateUserStack->P();
|
||||
|
||||
semAllocateUserStack->P();
|
||||
bit = memoryMap->Find();
|
||||
semAllocateUserStack->V();
|
||||
if ( bit == - 1 ) {
|
||||
DEBUG('x', "No slot avaible on User Stack\n");
|
||||
return -1;
|
||||
}
|
||||
int addr = memory - UserStackSize * bit;
|
||||
DEBUG('x', "Allocate User Stack bit %d, addr:%x\n", bit, addr);
|
||||
return addr;
|
||||
}
|
||||
|
||||
void
|
||||
AddrSpace::DeAllocateUserStack(int addr){
|
||||
int memory = numPages * PageSize;
|
||||
int memory = numPages * PageSize;
|
||||
int bit = (memory - addr) / UserStackSize;
|
||||
DEBUG('x', "Deallocate User Stack bit %d, addr:%x\n", bit, addr);
|
||||
semAllocateUserStack->P();
|
||||
memoryMap->Clear(bit);
|
||||
semAllocateUserStack->V();
|
||||
semAllocateUserStack->P();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue