user_thread #9
@ -11,7 +11,6 @@
|
||||
#include "uaddrspace.h"
|
||||
#include "zero.h"
|
||||
|
||||
|
||||
int syscallExecute(int syscallId, const struct cpu_state *userCtx)
|
||||
{
|
||||
|
||||
@ -146,6 +145,17 @@ int syscallExecute(int syscallId, const struct cpu_state *userCtx)
|
||||
|
||||
break;
|
||||
}
|
||||
case SYSCALL_ID_USLEEP: {
|
||||
unsigned int sleep;
|
||||
|
||||
ret = syscallGet1arg(userCtx, &sleep);
|
||||
if (ret)
|
||||
break;
|
||||
|
||||
ret = threadUsleep(sleep);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("Unknon syscall id %d\n", syscallId);
|
||||
ret = -ENOENT;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#define SYSCALL_ID_MMAP 7
|
||||
#define SYSCALL_ID_MUNMAP 8
|
||||
#define SYSCALL_ID_NEW_THREAD 9
|
||||
#define SYSCALL_ID_USLEEP 10
|
||||
|
||||
#ifdef __KERNEL__
|
||||
int syscallExecute(int syscallId, const struct cpu_state *user_ctx);
|
||||
|
@ -292,6 +292,11 @@ int threadYield()
|
||||
}
|
||||
|
||||
int threadMsleep(unsigned long msec)
|
||||
{
|
||||
return threadUsleep(msec*1000);
|
||||
}
|
||||
|
||||
int threadUsleep(unsigned long usec)
|
||||
{
|
||||
uint32_t flags;
|
||||
struct thread *next, *current;
|
||||
@ -299,12 +304,12 @@ int threadMsleep(unsigned long msec)
|
||||
disable_IRQs(flags);
|
||||
|
||||
current = currentThread;
|
||||
assertmsg(current->state == RUNNING, "thread %s is in state %d for %lu\n", current->name,
|
||||
current->state, msec);
|
||||
assertmsg(current->state == RUNNING, "thread %s is in state %d for %lu us\n", current->name,
|
||||
current->state, usec);
|
||||
|
||||
current->state = SLEEPING;
|
||||
current->sleepHaveTimeouted = 0;
|
||||
current->jiffiesSleeping = msecs_to_jiffies(msec);
|
||||
current->jiffiesSleeping = usecs_to_jiffies(usec);
|
||||
next = threadSelectNext();
|
||||
|
||||
assert(next != current);
|
||||
|
@ -83,6 +83,7 @@ int threadYield();
|
||||
int threadWait(struct thread *current, struct thread *next, unsigned long msec);
|
||||
int threadUnsched(struct thread *th);
|
||||
int threadMsleep(unsigned long msec);
|
||||
int threadUsleep(unsigned long usec);
|
||||
int threadOnJieffiesTick();
|
||||
struct thread *getCurrentThread();
|
||||
int threadAddThread(struct thread *th);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#define SYSCALL_ID_MMAP 7
|
||||
#define SYSCALL_ID_MUNMAP 8
|
||||
#define SYSCALL_ID_NEW_THREAD 9
|
||||
#define SYSCALL_ID_USLEEP 10
|
||||
|
||||
#ifdef __KERNEL__
|
||||
int syscallExecute(int syscallId, const struct cpu_state *user_ctx);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "swintr.h"
|
||||
#include "sys/mman.h"
|
||||
#include "syscall.h"
|
||||
#include "unistd.h"
|
||||
|
||||
int errno = 0;
|
||||
int memcmp(const void *aptr, const void *bptr, size_t size)
|
||||
@ -765,3 +766,7 @@ int new_thread(start_routine *func, void *arg, size_t stackSize)
|
||||
return syscall4(SYSCALL_ID_NEW_THREAD, (unsigned int)thread_runner, (unsigned int)func,
|
||||
(unsigned int)arg, stackSize);
|
||||
}
|
||||
|
||||
int usleep(useconds_t usec) {
|
||||
return syscall1(SYSCALL_ID_USLEEP, (unsigned int)usec);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "stddef.h"
|
||||
#include "sys/mman.h"
|
||||
#include "tiny.h"
|
||||
#include "unistd.h"
|
||||
|
||||
int func_help()
|
||||
{
|
||||
@ -122,6 +123,7 @@ int func_munmap()
|
||||
static void *print_hello(void *arg) {
|
||||
(void)arg;
|
||||
printf("Hello World from thread\n");
|
||||
usleep(100);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
4
userspace/unistd.h
Normal file
4
userspace/unistd.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
typedef unsigned int useconds_t;
|
||||
int usleep(useconds_t usec);
|
Loading…
Reference in New Issue
Block a user