Skip to content
Snippets Groups Projects
Commit 8c50e4a0 authored by John Hodge's avatar John Hodge
Browse files

Fixed compile errors, added Semaphore code

I will compile before committing
I will compile before committing
I will compile before committing
parent 4fc7efa6
No related merge requests found
...@@ -22,14 +22,24 @@ typedef Uint tGID; ...@@ -22,14 +22,24 @@ typedef Uint tGID;
typedef Sint64 tTimestamp; typedef Sint64 tTimestamp;
typedef struct sShortSpinlock tShortSpinlock; typedef struct sShortSpinlock tShortSpinlock;
typedef struct sMutex tMutex; typedef struct sMutex tMutex;
typedef struct sSemaphore tSemaphore;
struct sMutex { struct sMutex {
tShortSpinlock Protector; //!< Protector for the lock strucure tShortSpinlock Protector; //!< Protector for the lock strucure
const char *Name; //!< Human-readable name
struct sThread *volatile Owner; //!< Owner of the lock (set upon getting the lock) struct sThread *volatile Owner; //!< Owner of the lock (set upon getting the lock)
struct sThread *Waiting; //!< Waiting threads struct sThread *Waiting; //!< Waiting threads
struct sThread *LastWaiting; //!< Waiting threads struct sThread *LastWaiting; //!< Waiting threads
}; };
struct sSemaphore {
tShortSpinlock Protector; //!< Protector for the lock strucure
const char *Name; //!< Human-readable name
volatile int Value; //!< Current mutex value
struct sThread *Waiting; //!< Waiting threads
struct sThread *LastWaiting; //!< Waiting threads
};
// --- Helper Macros --- // --- Helper Macros ---
/** /**
* \name Helper Macros * \name Helper Macros
......
...@@ -74,6 +74,7 @@ enum { ...@@ -74,6 +74,7 @@ enum {
THREAD_STAT_ACTIVE, // Running and schedulable process THREAD_STAT_ACTIVE, // Running and schedulable process
THREAD_STAT_SLEEPING, // Message Sleep THREAD_STAT_SLEEPING, // Message Sleep
THREAD_STAT_MUTEXSLEEP, // Mutex Sleep THREAD_STAT_MUTEXSLEEP, // Mutex Sleep
THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep
THREAD_STAT_WAITING, // ??? (Waiting for a thread) THREAD_STAT_WAITING, // ??? (Waiting for a thread)
THREAD_STAT_PREINIT, // Being created THREAD_STAT_PREINIT, // Being created
THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed THREAD_STAT_ZOMBIE, // Died/Killed, but parent not informed
......
...@@ -62,6 +62,7 @@ tGID Threads_GetGID(void); ...@@ -62,6 +62,7 @@ tGID Threads_GetGID(void);
int Threads_SetGID(Uint *Errno, tUID ID); int Threads_SetGID(Uint *Errno, tUID ID);
void Threads_Dump(void); void Threads_Dump(void);
void Threads_DumpActive(void); void Threads_DumpActive(void);
void Mutex_Acquire(tMutex *Mutex); void Mutex_Acquire(tMutex *Mutex);
void Mutex_Release(tMutex *Mutex); void Mutex_Release(tMutex *Mutex);
int Mutex_IsLocked(tMutex *Mutex); int Mutex_IsLocked(tMutex *Mutex);
...@@ -1227,6 +1228,86 @@ int Mutex_IsLocked(tMutex *Mutex) ...@@ -1227,6 +1228,86 @@ int Mutex_IsLocked(tMutex *Mutex)
return Mutex->Owner != NULL; return Mutex->Owner != NULL;
} }
/**
* \brief Initialise the semaphore
* \param Value Initial value of the semaphore
* \param Label Symbolic name
*/
void Semaphore_Init(tSemaphore *Sem, int Value, const char *Label)
{
Sem->Value = Value;
Sem->Name = Label;
}
/**
* \brief Acquire a "item" from the semaphore
*/
void Semaphore_Wait(tSemaphore *Sem)
{
tThread *us;
SHORTLOCK( &Sem->Protector );
if( Sem->Value > 0 ) {
Sem->Value --;
SHORTREL( &Sem->Protector );
return ;
}
SHORTLOCK( &glThreadListLock );
// - Remove from active list
us = Threads_RemActive();
us->Next = NULL;
// - Mark as sleeping
us->Status = THREAD_STAT_SEMAPHORESLEEP;
us->WaitPointer = Sem;
// - Add to waiting
if(Sem->LastWaiting) {
Sem->LastWaiting->Next = us;
Sem->LastWaiting = us;
}
else {
Sem->Waiting = us;
Sem->LastWaiting = us;
}
SHORTREL( &glThreadListLock );
SHORTREL( &Sem->Protector );
while(us->Status == THREAD_STAT_MUTEXSLEEP) Threads_Yield();
// We're only woken when there's something avaliable
us->WaitPointer = NULL;
}
/**
* \brief Add an "item" to the semaphore
*/
void Semaphore_Signal(tSemaphore *Sem)
{
SHORTLOCK( &Sem->Protector );
Sem->Value ++;
if( Sem->Waiting )
{
tThread *toWake = Sem->Waiting;
Sem->Waiting = Sem->Waiting->Next; // Next!
// Reset ->LastWaiting to NULL if we have just removed the last waiting thread
if( Sem->Waiting == NULL )
Sem->LastWaiting = NULL;
// Wake new owner
SHORTLOCK( &glThreadListLock );
if( toWake->Status != THREAD_STAT_ACTIVE )
Threads_AddActive(toWake);
SHORTREL( &glThreadListLock );
// Decrement (the value is now "owned" by `toWake`)
Sem->Value --;
}
SHORTREL( &Sem->Protector );
}
// === EXPORTS === // === EXPORTS ===
EXPORT(Threads_GetUID); EXPORT(Threads_GetUID);
EXPORT(Threads_GetGID); EXPORT(Threads_GetGID);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* AcessOS 1 * AcessOS 1
* Video BIOS Extensions (Vesa) Driver * Video BIOS Extensions (Vesa) Driver
*/ */
#define DEBUG 0 #define DEBUG 1
#define VERSION 0x100 #define VERSION 0x100
#include <acess.h> #include <acess.h>
...@@ -93,13 +93,15 @@ int Vesa_Install(char **Arguments) ...@@ -93,13 +93,15 @@ int Vesa_Install(char **Arguments)
return MODULE_ERR_NOTNEEDED; return MODULE_ERR_NOTNEEDED;
} }
Log_Debug("VESA", "info->VideoModes = %04x:%04x", info->VideoModes.seg, info->VideoModes.ofs); //Log_Debug("VESA", "info->VideoModes = %04x:%04x", info->VideoModes.seg, info->VideoModes.ofs);
modes = (Uint16 *) VM8086_GetPointer(gpVesa_BiosState, info->VideoModes.seg, info->VideoModes.ofs); modes = (Uint16 *) VM8086_GetPointer(gpVesa_BiosState, info->VideoModes.seg, info->VideoModes.ofs);
// Read Modes // Read Modes
for( giVesaModeCount = 0; modes[giVesaModeCount] != 0xFFFF; giVesaModeCount++ ); for( giVesaModeCount = 0; modes[giVesaModeCount] != 0xFFFF; giVesaModeCount++ );
gVesa_Modes = (tVesa_Mode *)malloc( giVesaModeCount * sizeof(tVesa_Mode) ); gVesa_Modes = (tVesa_Mode *)malloc( giVesaModeCount * sizeof(tVesa_Mode) );
Log_Debug("VESA", "%i Modes", giVesaModeCount);
// Insert Text Mode // Insert Text Mode
gVesa_Modes[0].width = 80; gVesa_Modes[0].width = 80;
gVesa_Modes[0].height = 25; gVesa_Modes[0].height = 25;
......
...@@ -252,7 +252,6 @@ static const char *casIOCtls[] = { DRV_IOCTLNAMES, DRV_NETWORK_IOCTLNAMES, NULL ...@@ -252,7 +252,6 @@ static const char *casIOCtls[] = { DRV_IOCTLNAMES, DRV_NETWORK_IOCTLNAMES, NULL
*/ */
int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data) int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data)
{ {
int tmp;
ENTER("pNode iID pData", Node, ID, Data); ENTER("pNode iID pData", Node, ID, Data);
switch( ID ) switch( ID )
{ {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment