mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
waitpid: W_NOHANG
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
|
|
||||||
|
#define WNOHANG 1
|
||||||
|
#define KNOWN_FLAGS WNOHANG
|
||||||
|
|
||||||
syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int options) {
|
syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int options) {
|
||||||
syscallret_t ret = {
|
syscallret_t ret = {
|
||||||
.ret = -1
|
.ret = -1
|
||||||
@@ -11,7 +14,7 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
|||||||
|
|
||||||
// TODO address check
|
// TODO address check
|
||||||
// TODO implement these
|
// TODO implement these
|
||||||
__assert(options == 0);
|
__assert((options & ~KNOWN_FLAGS) == 0);
|
||||||
__assert(pid == -1 || pid > 0);
|
__assert(pid == -1 || pid > 0);
|
||||||
|
|
||||||
thread_t *thread = _cpu()->thread;
|
thread_t *thread = _cpu()->thread;
|
||||||
@@ -30,7 +33,11 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
spinlock_release(&proc->lock);
|
spinlock_release(&proc->lock);
|
||||||
if (semaphore_wait(&proc->waitsem, true)) {
|
if ((options & WNOHANG) && semaphore_test(&proc->waitsem) == false) {
|
||||||
|
ret.errno = 0;
|
||||||
|
ret.ret = 0;
|
||||||
|
return ret;
|
||||||
|
} else if ((options & WNOHANG) == 0 && semaphore_wait(&proc->waitsem, true)) {
|
||||||
ret.errno = EINTR;
|
ret.errno = EINTR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user