*/
#include <stddef.h>
+#include <stdbool.h>
#include <arch.h>
#ifndef HALT_CPU
typedef Sint64 tTimestamp; //!< Timestamp (miliseconds since 00:00 1 Jan 1970)
typedef Sint64 tTime; //!< Same again
typedef struct sShortSpinlock tShortSpinlock; //!< Opaque (kinda) spinlock
-typedef int bool; //!< Boolean type
typedef Uint64 off_t; //!< VFS Offset
typedef struct { char _[PAGE_SIZE];} tPage; // Representation of a page for pointer arithmatic
*/
extern void Time_RemoveTimer(tTimer *Timer);
+/**
+ * Schedule a THREAD_EVENT_TIMER to fire in \a Delay milliseconds
+ */
+extern void Time_ScheduleEvent(int Delay);
+
/**
* \brief Wait for a period of milliseconds
*/
void *Head;
void *Tail;
struct sThread *Sleeper;
+ struct sThread *SleepTail;
};
extern void Workqueue_Init(tWorkqueue *Queue, const char *Name, size_t NextOfset);
}
*ListTail = us;
}
- else {
+ else if( ListHead ) {
+ us->Next = *ListHead;
*ListHead = us;
}
+ else {
+ // Nothing
+ }
//if( Proc_ThreadSync(us) )
// return ;
LOG("%p deallocated %p", __builtin_return_address(0), Timer);
}
+void Time_ScheduleEvent(int Delay)
+{
+ tTimer *t = &Proc_GetCurThread()->ThreadTimer;
+ Time_RemoveTimer(t);
+ Time_InitTimer(t, NULL, NULL);
+ Time_ScheduleTimer(t, Delay);
+}
+
/**
* \fn void Time_Delay(int Delay)
* \brief Delay for a small ammount of time
void Time_Delay(int Delay)
{
LOG("(%i)", Delay);
- tTimer *t = &Proc_GetCurThread()->ThreadTimer;
- Time_InitTimer(t, NULL, NULL);
- Time_ScheduleTimer(t, Delay);
+ Threads_ClearEvent(THREAD_EVENT_TIMER);
+ Time_ScheduleEvent(Delay);
Threads_WaitEvents(THREAD_EVENT_TIMER);
}
{
Queue->Name = Name;
Queue->NextOffset = NextOfset;
+ Queue->Sleeper = NULL;
+ Queue->SleepTail = NULL;
}
void *Workqueue_GetWork(tWorkqueue *Queue)
Threads_int_Sleep(THREAD_STAT_QUEUESLEEP,
Queue, 0,
- &Queue->Sleeper, NULL, &Queue->Protector);
+ &Queue->Sleeper, &Queue->SleepTail, &Queue->Protector);
}
}
if( Queue->Sleeper )
{
- if( Queue->Sleeper->Status != THREAD_STAT_ACTIVE )
- Threads_AddActive(Queue->Sleeper);
- Queue->Sleeper = NULL;
+ ASSERTC( Queue->Sleeper->Status, !=, THREAD_STAT_ACTIVE );
+ tThread *next_sleeper = Queue->Sleeper->Next;
+ Threads_AddActive(Queue->Sleeper);
+ Queue->Sleeper = next_sleeper;
+ if(!next_sleeper)
+ Queue->SleepTail = NULL;
}
SHORTREL(&Queue->Protector);
}