mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[kernel] Change thread_sleep arg from time to duration
It seems more common to want to sleep for a duration than to sleep to a specific time. Change the implementation to not make the process look up the current time first. (Plus, there's no current syscall to do so)
This commit is contained in:
@@ -18,6 +18,6 @@ object thread : object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
method sleep [static] {
|
method sleep [static] {
|
||||||
param until uint64
|
param duration uint64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <j6/errors.h>
|
#include <j6/errors.h>
|
||||||
#include <j6/types.h>
|
#include <j6/types.h>
|
||||||
|
|
||||||
|
#include "clock.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "objects/process.h"
|
#include "objects/process.h"
|
||||||
#include "objects/thread.h"
|
#include "objects/thread.h"
|
||||||
@@ -47,11 +48,13 @@ thread_kill(thread *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
j6_status_t
|
j6_status_t
|
||||||
thread_sleep(uint64_t til)
|
thread_sleep(uint64_t duration)
|
||||||
{
|
{
|
||||||
thread &th = thread::current();
|
thread &th = thread::current();
|
||||||
log::debug(logs::task, "Thread %llx sleeping until %llu", th.koid(), til);
|
|
||||||
|
|
||||||
|
uint64_t til = clock::get().value() + duration;
|
||||||
|
|
||||||
|
log::debug(logs::task, "Thread %llx sleeping until %llu", th.koid(), til);
|
||||||
th.set_wake_timeout(til);
|
th.set_wake_timeout(til);
|
||||||
th.block();
|
th.block();
|
||||||
return j6_status_ok;
|
return j6_status_ok;
|
||||||
|
|||||||
Reference in New Issue
Block a user