Various bugfixes to Thread_Wait and the pthread library
This commit is contained in:
parent
9460089573
commit
1ceea3c677
@ -2,17 +2,17 @@
|
||||
#ifndef __ERRNO_H__
|
||||
#define __ERRNO_H__
|
||||
|
||||
#define EIO 0xBAD1
|
||||
#define EBADF 0xBAD2
|
||||
#define EINVAL 0xBAD3
|
||||
#define EFAULT 0xBAD4
|
||||
#define ENOMEM 0xBAD5
|
||||
#define ENOENT 0xBAD6
|
||||
#define ENOTDIR 0xBAD7
|
||||
#define ENAMETOOLONG 0xBAD8
|
||||
#define ENOSYS 0xBAD9
|
||||
#define EAGAIN 0xBADA
|
||||
#define EBUSY 0xBADB
|
||||
#define EIO 0x1BAD0001
|
||||
#define EBADF 0x1BAD0002
|
||||
#define EINVAL 0x1BAD0003
|
||||
#define EFAULT 0x1BAD0004
|
||||
#define ENOMEM 0x1BAD0005
|
||||
#define ENOENT 0x1BAD0006
|
||||
#define ENOTDIR 0x1BAD0007
|
||||
#define ENAMETOOLONG 0x1BAD0008
|
||||
#define ENOSYS 0x1BAD0009
|
||||
#define EAGAIN 0x1BAD000A
|
||||
#define EBUSY 0x1BAD000B
|
||||
|
||||
#endif /* __ERRNO_H__ */
|
||||
|
||||
|
@ -90,7 +90,9 @@ pthreadCreateHelper(void *arg)
|
||||
{
|
||||
struct pthread *thr = (struct pthread *)arg;
|
||||
|
||||
OSThreadExit((uint64_t)(thr->entry)(thr->arg));
|
||||
thr->result = (thr->entry)(thr->arg);
|
||||
|
||||
OSThreadExit(0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -141,8 +143,8 @@ int
|
||||
pthread_join(pthread_t thread, void **value_ptr)
|
||||
{
|
||||
struct pthread *thr = thread;
|
||||
uint64_t status = OSThreadWait(thr->tid);
|
||||
if (status != 0) {
|
||||
uint64_t status = OSThreadWait(0);//thr->tid);
|
||||
if (SYSCALL_ERRCODE(status) != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -365,13 +365,13 @@ Syscall_ThreadCreate(uint64_t rip, uint64_t arg)
|
||||
|
||||
Thread_Release(curThread);
|
||||
if (newThread == NULL) {
|
||||
return -1;
|
||||
return SYSCALL_PACK(ENOMEM, 0);
|
||||
}
|
||||
|
||||
threadId = newThread->tid;
|
||||
Sched_SetRunnable(newThread);
|
||||
|
||||
return threadId;
|
||||
return SYSCALL_PACK(0, threadId);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
@ -455,7 +455,7 @@ Syscall_ThreadWait(uint64_t tid)
|
||||
while (1) {
|
||||
Semaphore_Acquire(&cur->proc->zombieSemaphore);
|
||||
status = Thread_Wait(cur, tid);
|
||||
if (status != 0) {
|
||||
if (SYSCALL_ERRCODE(status) != EAGAIN) {
|
||||
Thread_Release(cur);
|
||||
return status;
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <sys/kassert.h>
|
||||
#include <sys/kconfig.h>
|
||||
#include <sys/kdebug.h>
|
||||
@ -382,13 +385,13 @@ Thread_Wait(Thread *thr, uint64_t tid)
|
||||
if (tid == 0) {
|
||||
t = TAILQ_FIRST(&thr->proc->zombieQueue);
|
||||
if (!t) {
|
||||
return 0;
|
||||
return SYSCALL_PACK(EAGAIN, 0);
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&thr->proc->zombieQueue, t, schedQueue);
|
||||
status = t->exitValue;
|
||||
Thread_Release(t);
|
||||
return status;
|
||||
return SYSCALL_PACK(0, status);
|
||||
}
|
||||
|
||||
TAILQ_FOREACH(t, &thr->proc->zombieQueue, schedQueue) {
|
||||
@ -396,7 +399,7 @@ Thread_Wait(Thread *thr, uint64_t tid)
|
||||
TAILQ_REMOVE(&thr->proc->zombieQueue, t, schedQueue);
|
||||
status = t->exitValue;
|
||||
Thread_Release(t);
|
||||
return status;
|
||||
return SYSCALL_PACK(0, status);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <core/mutex.h>
|
||||
|
||||
void *
|
||||
thread_simple(void *arg)
|
||||
@ -26,10 +28,8 @@ main(int argc, const char *argv[])
|
||||
// Simple thread test
|
||||
printf("simple test\n");
|
||||
status = pthread_create(&thr, NULL, thread_simple, NULL);
|
||||
printf("status %d\n", status);
|
||||
assert(status == 0);
|
||||
status = pthread_join(thr, &result);
|
||||
printf("status %d\n", status);
|
||||
assert(status == 0);
|
||||
assert(result == NULL);
|
||||
|
||||
@ -41,6 +41,8 @@ main(int argc, const char *argv[])
|
||||
assert(status == 0);
|
||||
assert(result == (void *)1);
|
||||
|
||||
// Mutex test
|
||||
|
||||
printf("Success!\n");
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user