scheduler: sched_usleep

This commit is contained in:
Matheus
2023-10-15 20:58:10 -03:00
parent 676be91ac0
commit 6d8c0c30cf
3 changed files with 15 additions and 0 deletions
+1
View File
@@ -16,6 +16,7 @@
#define IPL_MAX 0
#define IPL_TIMER 1
#define IPL_KEYBOARD 2
#define IPL_NET 400
#define IPL_DISK 500
#define IPL_DPC 900
#define IPL_NORMAL 1000
+1
View File
@@ -90,5 +90,6 @@ thread_t *sched_newthread(void *ip, size_t kstacksize, int priority, proc_t *pro
void sched_destroyproc(proc_t *);
void sched_destroythread(thread_t *);
void sched_targetcpu(struct cpu_t *cpu);
void sched_sleepus(size_t us);
#endif
+13
View File
@@ -387,6 +387,19 @@ void sched_targetcpu(cpu_t *cpu) {
interrupt_set(intstatus);
}
static void timeout(context_t *, dpcarg_t arg) {
thread_t *thread = arg;
sched_wakeup(thread, 0);
}
void sched_sleepus(size_t us) {
timerentry_t sleepentry = {0};
sched_preparesleep(false);
timer_insert(_cpu()->timer, &sleepentry, timeout, _cpu()->thread, us, false);
sched_yield();
}
void sched_init() {
threadcache = slab_newcache(sizeof(thread_t), 0, NULL, NULL);
__assert(threadcache);