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