TD2 I.5 first working version of Thread
Add semaphore to PutChar and GetChar
This commit is contained in:
parent
c4a2d25163
commit
6bd3e1338f
8 changed files with 95 additions and 4 deletions
|
@ -6,6 +6,8 @@
|
|||
|
||||
static Semaphore *readAvail;
|
||||
static Semaphore *writeDone;
|
||||
static Semaphore *m_PutChar;
|
||||
static Semaphore *m_GetChar;
|
||||
|
||||
static void ReadAvailHandler(void *arg) { (void) arg; readAvail->V(); }
|
||||
static void WriteDoneHandler(void *arg) { (void) arg; writeDone->V(); }
|
||||
|
@ -15,6 +17,11 @@ ConsoleDriver::ConsoleDriver(const char *in, const char *out)
|
|||
readAvail = new Semaphore("read avail", 0);
|
||||
writeDone = new Semaphore("write done", 0);
|
||||
console = new Console (in, out, ReadAvailHandler, WriteDoneHandler, NULL);
|
||||
|
||||
// Add these semaphores because we had problems with threads
|
||||
// Assert error on putBusy
|
||||
m_PutChar = new Semaphore("PutChar", 1);
|
||||
m_GetChar = new Semaphore("GetChar", 1);
|
||||
}
|
||||
|
||||
ConsoleDriver::~ConsoleDriver()
|
||||
|
@ -22,18 +29,24 @@ ConsoleDriver::~ConsoleDriver()
|
|||
delete console;
|
||||
delete writeDone;
|
||||
delete readAvail;
|
||||
delete m_PutChar;
|
||||
delete m_GetChar;
|
||||
}
|
||||
|
||||
void ConsoleDriver::PutChar( int ch)
|
||||
{
|
||||
m_PutChar->P();
|
||||
console->TX(ch);
|
||||
writeDone->P();
|
||||
writeDone->P();
|
||||
m_PutChar->V();
|
||||
}
|
||||
|
||||
int ConsoleDriver::GetChar()
|
||||
{
|
||||
m_GetChar->P();
|
||||
readAvail->P();
|
||||
int ch = console->RX();
|
||||
m_GetChar->V();
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue