#include <usr/lunaix/threads.h>
-#include <sys/abi.h>
-#include <sys/mm/mm_defs.h>
+#include <asm/abi.h>
+#include <asm/mm_defs.h>
LOG_MODULE("THREAD")
return align_stack(ptep_va(ptep, LFT_SIZE) - 1);
}
+static int
+__thread_putsleep(int seconds)
+{
+ if (!seconds) {
+ return 0;
+ }
+
+ struct scheduler* sched;
+ time_t systime;
+ struct haybed* bed;
+
+ sched = scheduler();
+ systime = clock_systime() / 1000;
+ bed = ¤t_thread->sleep;
+
+ if (bed->wakeup_time) {
+ return (bed->wakeup_time - systime);
+ }
+
+ bed->wakeup_time = systime + seconds;
+
+ if (llist_empty(&bed->sleepers)) {
+ llist_append(&sched->sleepers, &bed->sleepers);
+ }
+
+ block_current_thread();
+ return seconds;
+}
+
void
thread_release_mem(struct thread* thread)
{
stats->last_entry = now;
}
+void
+kthread_spawn(ptr_t entry)
+{
+ assert(kernel_process(__current));
+
+ struct thread* th = create_thread(__current, false);
+
+ assert(th);
+ start_thread(th, entry);
+ detach_thread(th);
+}
+
+void
+kthread_sleep(int seconds)
+{
+ if (__thread_putsleep(seconds))
+ yield_current();
+}
+
__DEFINE_LXSYSCALL3(int, th_create, tid_t*, tid,
struct uthread_param*, thparam, void*, entry)
{
return 0;
}
+
+__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
+{
+ int sec;
+
+ sec = __thread_putsleep(seconds);
+ store_retval(seconds);
+
+ if (sec)
+ schedule();
+
+ return 0;
+}
\ No newline at end of file