diff options
author | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-02-18 16:48:11 +0000 |
---|---|---|
committer | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-02-18 16:48:11 +0000 |
commit | 8182e7cfe7d9c60567e48b876282594395062530 (patch) | |
tree | bb743948c6e926539b030102b804b5708222e8d4 /mdk-stage1/dietlibc/libpthread | |
parent | c93f95560d3fde9eaefcc62c454c67b8b5626fa7 (diff) | |
download | drakx-8182e7cfe7d9c60567e48b876282594395062530.tar drakx-8182e7cfe7d9c60567e48b876282594395062530.tar.gz drakx-8182e7cfe7d9c60567e48b876282594395062530.tar.bz2 drakx-8182e7cfe7d9c60567e48b876282594395062530.tar.xz drakx-8182e7cfe7d9c60567e48b876282594395062530.zip |
Merge in CVS dietlibc 0.21 for IA-64 and X86-64 support. However, drop the
following architectures we currently don't support: arm, mips, mipsel, parisc,
s390, sparc64.
Diffstat (limited to 'mdk-stage1/dietlibc/libpthread')
54 files changed, 356 insertions, 175 deletions
diff --git a/mdk-stage1/dietlibc/libpthread/CHANGES b/mdk-stage1/dietlibc/libpthread/CHANGES index d39d990ba..63376623b 100644 --- a/mdk-stage1/dietlibc/libpthread/CHANGES +++ b/mdk-stage1/dietlibc/libpthread/CHANGES @@ -1,6 +1,12 @@ This is the pthread implementation of dietlibc. Written from scratch by Olaf Dreesen. +Mon Aug 6 15:46:39 MEST 2001 + + Ups... did the wrong error handling... the error is returned not put to + errno... + probably thread_key is not SMP save... + Thu Apr 12 16:47:12 MEST 2001 added conditional variables... diff --git a/mdk-stage1/dietlibc/libpthread/Makefile b/mdk-stage1/dietlibc/libpthread/Makefile index 06420f43a..f2ab8d8dc 100644 --- a/mdk-stage1/dietlibc/libpthread/Makefile +++ b/mdk-stage1/dietlibc/libpthread/Makefile @@ -12,14 +12,14 @@ VPATH=../$(ARCH)/ PTHREAD_OBJS = \ __testandset.o \ \ - thread_internal.o \ - thread_key.o \ + pthread_internal.o \ + pthread_key.o \ \ pthread_once.o pthread_spinlock.o \ \ pthread_create.o pthread_detach.o \ pthread_join.o pthread_self.o \ - pthread_exit.o \ + pthread_exit.o pthread_equal.o \ \ pthread_cleanup_push.o \ pthread_cleanup_pop.o \ @@ -72,6 +72,7 @@ PTHREAD_OBJS = \ pthread_sys_create.o \ pthread_sys_fcntl.o \ pthread_sys_fsync.o \ + pthread_sys_fdatasync.o \ pthread_sys_nanosleep.o \ pthread_sys_logging.o \ pthread_sys_open.o \ diff --git a/mdk-stage1/dietlibc/libpthread/README b/mdk-stage1/dietlibc/libpthread/README index 3139c731d..ee85a572d 100644 --- a/mdk-stage1/dietlibc/libpthread/README +++ b/mdk-stage1/dietlibc/libpthread/README @@ -3,7 +3,7 @@ LIBPTHREAD This is the pthread implementation of dietlibc. Written from scratch by Olaf Dreesen. -1. STATUS: incomplete but should work (or not... I had a lot of heisen-bugs...) +1. STATUS: near complete and should work (or not... I had a lot of heisen-bugs...) On non i386 archs the kernel header have major differences... NO workaround yet for this problems... @@ -15,13 +15,7 @@ Nested thread creation is now working fine... 2. HOW-TO make this lib: - 1. generate the dietlibc in the parent directory. - and make sure you have WANT_THREAD_SAVE active in the file: - dietfeatures.h - - 2. change back here and type make - - and then you should have a libpthread.a + it is a standard dietlibc helper lib... 3. NOTES diff --git a/mdk-stage1/dietlibc/libpthread/pthread_atfork.c b/mdk-stage1/dietlibc/libpthread/pthread_atfork.c index 2dc612dcc..70ca9f162 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_atfork.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_atfork.c @@ -36,7 +36,7 @@ int pthread_atfork(void (*prepare)(void), __pthread_unlock(&__atfork_struct_lock); __NO_ASYNC_CANCEL_END; - if (ret) (*(__errno_location()))=ENOMEM; + if (ret) ret=ENOMEM; return ret; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_attr_init.c b/mdk-stage1/dietlibc/libpthread/pthread_attr_init.c index 726e88fe5..fbcefa3bd 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_attr_init.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_attr_init.c @@ -1,3 +1,4 @@ +#include <string.h> #include <unistd.h> #include <errno.h> diff --git a/mdk-stage1/dietlibc/libpthread/pthread_attr_setdetachstate.c b/mdk-stage1/dietlibc/libpthread/pthread_attr_setdetachstate.c index 690ad5f8e..f5eab5816 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_attr_setdetachstate.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_attr_setdetachstate.c @@ -13,6 +13,5 @@ int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) attr->__detachstate=detachstate; return 0; } - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_attr_setinheritsched.c b/mdk-stage1/dietlibc/libpthread/pthread_attr_setinheritsched.c index f38e6e35e..0b7a691e7 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_attr_setinheritsched.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_attr_setinheritsched.c @@ -13,6 +13,5 @@ int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit) attr->__inheritsched=inherit; return 0; } - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedparam.c b/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedparam.c index 833c0111b..a3e5a9b4a 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedparam.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedparam.c @@ -12,12 +12,11 @@ int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *p attr->__schedparam.sched_priority=0; return 0; } - if (((attr->__schedpolicy == SCHED_RR) || (attr->__schedpolicy == SCHED_RR)) + if (((attr->__schedpolicy == SCHED_RR) || (attr->__schedpolicy == SCHED_FIFO)) && ((param->sched_priority > 0) && (param->sched_priority < 100))) { attr->__schedparam.sched_priority=param->sched_priority; return 0; } - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedpolicy.c b/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedpolicy.c index e845bca32..227d3f7ad 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedpolicy.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_attr_setschedpolicy.c @@ -17,9 +17,8 @@ int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) attr->__schedpolicy=policy; return 0; } - (*(__errno_location()))=ENOTSUP; + return ENOTSUP; } else - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_attr_setscope.c b/mdk-stage1/dietlibc/libpthread/pthread_attr_setscope.c index 39088c9b2..9be11ca2d 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_attr_setscope.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_attr_setscope.c @@ -11,8 +11,7 @@ int pthread_attr_setscope(pthread_attr_t *attr, int scope) if (scope==PTHREAD_SCOPE_SYSTEM) return 0; if (scope==PTHREAD_SCOPE_PROCESS) - (*(__errno_location()))=ENOTSUP; + return ENOTSUP; else - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_attr_setstacksize.c b/mdk-stage1/dietlibc/libpthread/pthread_attr_setstacksize.c index cfbab7747..1a0aae929 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_attr_setstacksize.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_attr_setstacksize.c @@ -12,6 +12,5 @@ int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) attr->__stacksize=stacksize; return 0; } - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_cancel.c b/mdk-stage1/dietlibc/libpthread/pthread_cancel.c index 4c87a3ed1..c0ae60349 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_cancel.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_cancel.c @@ -14,14 +14,12 @@ int pthread_cancel(pthread_t th) j=__find_thread_id(th); if (j==-1) { - (*(__errno_location()))=ESRCH; - return -1; + return ESRCH; } thread = __get_thread_struct(j); if (thread==0) { - (*(__errno_location()))=ESRCH; - return -1; + return ESRCH; } if (thread->cancelstate!=PTHREAD_CANCEL_DISABLE) { diff --git a/mdk-stage1/dietlibc/libpthread/pthread_cond_broadcast.c b/mdk-stage1/dietlibc/libpthread/pthread_cond_broadcast.c index d3c2274f3..776e0adfc 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_cond_broadcast.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_cond_broadcast.c @@ -10,14 +10,17 @@ int pthread_cond_broadcast(pthread_cond_t *cond) __THREAD_INIT(); + __NO_ASYNC_CANCEL_BEGIN; __pthread_lock(&(cond->lock)); - while ((tmp=cond->wait_chain)) { - cond->wait_chain=tmp->waitnext; + + for (tmp=cond->wait_chain;tmp;tmp=tmp->waitnext) { tmp->waitnext=0; tmp->waiting=0; } - __pthread_unlock(&(cond->lock)); + cond->wait_chain=0; + __pthread_unlock(&(cond->lock)); + __NO_ASYNC_CANCEL_STOP; return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_cond_destroy.c b/mdk-stage1/dietlibc/libpthread/pthread_cond_destroy.c index 9a6cc4f0b..b553b41df 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_cond_destroy.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_cond_destroy.c @@ -1,3 +1,4 @@ +#include <string.h> #include <unistd.h> #include <errno.h> @@ -9,8 +10,7 @@ int pthread_cond_destroy(pthread_cond_t *cond) __THREAD_INIT(); if (cond->wait_chain) { - (*__errno_location())=EBUSY; - return 1; + return EBUSY; } memset(cond,0,sizeof(pthread_cond_t)); diff --git a/mdk-stage1/dietlibc/libpthread/pthread_cond_init.c b/mdk-stage1/dietlibc/libpthread/pthread_cond_init.c index 20b38bef2..76dd5cb97 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_cond_init.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_cond_init.c @@ -1,3 +1,4 @@ +#include <string.h> #include <unistd.h> #include <errno.h> diff --git a/mdk-stage1/dietlibc/libpthread/pthread_cond_signal.c b/mdk-stage1/dietlibc/libpthread/pthread_cond_signal.c index 60bf2119c..02a3c028e 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_cond_signal.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_cond_signal.c @@ -10,9 +10,11 @@ int pthread_cond_signal(pthread_cond_t *cond) __THREAD_INIT(); + __NO_ASYNC_CANCEL_BEGIN; __pthread_lock(&(cond->lock)); if ((tmp=cond->wait_chain)) cond->wait_chain=tmp->waitnext; __pthread_unlock(&(cond->lock)); + __NO_ASYNC_CANCEL_STOP; if (tmp) { tmp->waitnext=0; diff --git a/mdk-stage1/dietlibc/libpthread/pthread_cond_timedwait.c b/mdk-stage1/dietlibc/libpthread/pthread_cond_timedwait.c index 6613f2ca9..71d80bdb5 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_cond_timedwait.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_cond_timedwait.c @@ -9,13 +9,14 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, { _pthread_descr tmp; _pthread_descr this; - int ret; + int ret=0; __THREAD_INIT(); this=__thread_self(); /* put in wait-chain */ + __NO_ASYNC_CANCEL_BEGIN; __pthread_lock(&(cond->lock)); this->waiting=1; if (cond->wait_chain) { @@ -23,21 +24,51 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, tmp->waitnext=this; } else cond->wait_chain=this; __pthread_unlock(&(cond->lock)); + __NO_ASYNC_CANCEL_STOP; - /* Aeh yeah / wait till signal */ + /* Aeh yeah / wait till cond-signal OR timeout */ pthread_mutex_unlock(mutex); - ret=nanosleep(abstime,0); + while (this->waiting) { + struct timeval tv; + gettimeofday(&tv,0); + if ((abstime->tv_sec <= tv.tv_sec) && (abstime->tv_nsec <= (tv.tv_usec*1000))) { + ret = 1; + break; + } + __thread_wait_some_time(); + if (this->canceled) break; /* a cancel */ + } pthread_mutex_lock(mutex); - __TEST_CANCEL(); - - if (ret) { - if ((*__errno_location())!=EINTR) return -1; - return 0; + __NO_ASYNC_CANCEL_BEGIN; + __pthread_lock(&(cond->lock)); + if (this->waiting) { /* still waiting -> TIMEOUT or SIGNAL */ + _pthread_descr prev; + /* remove from wait-chain */ + prev=cond->wait_chain; + if ((prev=cond->wait_chain)==this) { + cond->wait_chain=this->waitnext; + } else { + for (tmp=prev->waitnext;tmp;prev=tmp,tmp=prev->waitnext) { + if (tmp==this) { + prev->waitnext=this->waitnext; + break; + } + } + } + this->waiting=0; + this->waitnext=0; } + __pthread_unlock(&(cond->lock)); + __NO_ASYNC_CANCEL_END; + + if (ret) return ETIMEDOUT; - (*__errno_location())=ETIMEDOUT; - return -1; + { + register int err = (*__errno_location()); + if (err==EINTR) return err; + } + return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_cond_wait.c b/mdk-stage1/dietlibc/libpthread/pthread_cond_wait.c index 0c6c0ae13..8db49e840 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_cond_wait.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_cond_wait.c @@ -14,6 +14,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) this=__thread_self(); /* put in wait-chain */ + __NO_ASYNC_CANCEL_BEGIN; __pthread_lock(&(cond->lock)); this->waiting=1; if (cond->wait_chain) { @@ -21,16 +22,37 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) tmp->waitnext=this; } else cond->wait_chain=this; __pthread_unlock(&(cond->lock)); + __NO_ASYNC_CANCEL_STOP; /* Aeh yeah / wait till signal */ pthread_mutex_unlock(mutex); while (this->waiting) { __thread_wait_some_time(); - if (this->canceled) this->waiting=0; /* we got a cancel signal */ + if (this->canceled) break; /* we got a cancel signal */ } pthread_mutex_lock(mutex); - __TEST_CANCEL(); + __NO_ASYNC_CANCEL_BEGIN; + __pthread_lock(&(cond->lock)); + if (this->waiting) { /* still waiting -> SIGNAL */ + _pthread_descr prev; + /* remove from wait-chain */ + prev=cond->wait_chain; + if ((prev=cond->wait_chain)==this) { + cond->wait_chain=this->waitnext; + } else { + for (tmp=prev->waitnext;tmp;prev=tmp,tmp=prev->waitnext) { + if (tmp==this) { + prev->waitnext=this->waitnext; + break; + } + } + } + this->waiting=0; + this->waitnext=0; + } + __pthread_unlock(&(cond->lock)); + __NO_ASYNC_CANCEL_END; return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_create.c b/mdk-stage1/dietlibc/libpthread/pthread_create.c index b4a499081..714c2bf4b 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_create.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_create.c @@ -15,21 +15,20 @@ int pthread_create (pthread_t *thread, const pthread_attr_t *attr, __THREAD_INIT(); if (start_routine==0) { - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } td = __thread_get_free(); if (td) { + td->go.__spinlock=PTHREAD_SPIN_LOCKED; if (!(attr)) { pthread_attr_init(&default_attr); attr=&default_attr; } if ((td->policy!=SCHED_OTHER)&&(td->priority==0)) { - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } if (attr->__inheritsched==PTHREAD_INHERIT_SCHED) { @@ -48,14 +47,17 @@ int pthread_create (pthread_t *thread, const pthread_attr_t *attr, td->stack_size = attr->__stacksize; - if (!(td->stack_addr)) { + if (!(attr->__stackaddr)) { char *stack=(char*)malloc(td->stack_size); if (!(stack)) { - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } td->stack_begin = stack; +#ifdef __parisc__ + td->stack_addr = stack; +#else td->stack_addr = stack+td->stack_size; +#endif } else { td->stack_begin = 0; td->stack_addr = attr->__stackaddr; @@ -65,12 +67,15 @@ int pthread_create (pthread_t *thread, const pthread_attr_t *attr, if (ret>1) *thread=ret; - else + else { + ++td->exited; /* mark as exited */ __thread_cleanup(td); + if (ret<0) return (*(__errno_location())); + return EAGAIN; + } } else - (*(__errno_location()))=EAGAIN; + return EAGAIN; - if (ret<2) return -1; - return ret; + return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_detach.c b/mdk-stage1/dietlibc/libpthread/pthread_detach.c index c07280389..2f72b97a7 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_detach.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_detach.c @@ -13,19 +13,12 @@ int pthread_detach(pthread_t th) j=__find_thread_id(th); if (j==-1) { - (*(__errno_location()))=ESRCH; - return -1; + return ESRCH; } thread = __get_thread_struct(j); - if (thread==0) { - (*(__errno_location()))=ESRCH; - return -1; - } - if (thread->detached) { - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } if (!thread->joined) { diff --git a/mdk-stage1/dietlibc/libpthread/pthread_equal.c b/mdk-stage1/dietlibc/libpthread/pthread_equal.c new file mode 100644 index 000000000..d054d86ed --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_equal.c @@ -0,0 +1,3 @@ +#include <pthread.h> + +int pthread_equal(pthread_t thread1, pthread_t thread2) { return (thread1==thread2); } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_errno.c b/mdk-stage1/dietlibc/libpthread/pthread_errno.c new file mode 100644 index 000000000..d035544ad --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_errno.c @@ -0,0 +1,5 @@ +int errno; + +#include "dietwarning.h" + +link_warning("errno","\e[1;33;41m>>> your multithreaded code uses errno! <<<\e[0m"); diff --git a/mdk-stage1/dietlibc/libpthread/pthread_fdglue2.c b/mdk-stage1/dietlibc/libpthread/pthread_fdglue2.c new file mode 100644 index 000000000..d73c84220 --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_fdglue2.c @@ -0,0 +1,16 @@ +#include "dietstdio.h" +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <stdlib.h> +#include <pthread.h> +#include <errno.h> + +extern int __stdio_atexit; +extern FILE* __stdio_init_file_nothreads(int fd,int closeonerror); + +FILE* __stdio_init_file(int fd,int closeonerror) { + FILE *tmp=__stdio_init_file_nothreads(fd,closeonerror); + if (tmp) pthread_mutex_init(&tmp->m,0); + return tmp; +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_fgetc.c b/mdk-stage1/dietlibc/libpthread/pthread_fgetc.c new file mode 100644 index 000000000..34e79e0fe --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_fgetc.c @@ -0,0 +1,10 @@ +#include "dietstdio.h" +#include <unistd.h> + +int fgetc(FILE *stream) { + int tmp; + pthread_mutex_lock(&stream->m); + tmp=fgetc_unlocked(stream); + pthread_mutex_unlock(&stream->m); + return tmp; +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_flockfile.c b/mdk-stage1/dietlibc/libpthread/pthread_flockfile.c new file mode 100644 index 000000000..72131ffb1 --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_flockfile.c @@ -0,0 +1,5 @@ +#include "dietstdio.h" + +void flockfile(FILE* f) { + pthread_mutex_lock(&f->m); +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_fputc.c b/mdk-stage1/dietlibc/libpthread/pthread_fputc.c new file mode 100644 index 000000000..82344b107 --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_fputc.c @@ -0,0 +1,9 @@ +#include <dietstdio.h> + +int fputc(int c, FILE *stream) { + int tmp; + pthread_mutex_lock(&stream->m); + tmp=fputc_unlocked(c,stream); + pthread_mutex_unlock(&stream->m); + return tmp; +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_funlockfile.c b/mdk-stage1/dietlibc/libpthread/pthread_funlockfile.c new file mode 100644 index 000000000..beae058af --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_funlockfile.c @@ -0,0 +1,5 @@ +#include "dietstdio.h" + +void funlockfile(FILE* f) { + pthread_mutex_unlock(&f->m); +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_getschedparam.c b/mdk-stage1/dietlibc/libpthread/pthread_getschedparam.c new file mode 100644 index 000000000..aaaba4458 --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_getschedparam.c @@ -0,0 +1,22 @@ +#include <unistd.h> +#include <errno.h> + +#include <pthread.h> +#include "thread_internal.h" + +int pthread_getschedparam(pthread_t target_thread, int *policy, struct sched_param *param) +{ + int p; + __THREAD_INIT(); + + if (__find_thread_id(target_thread)<0) { + return ESRCH; + } + + if (((p=sched_getscheduler(target_thread))==-1)|| + (sched_getparam(target_thread,param) ==-1)) { + return (*(__errno_location())); + } + *policy=p; + return 0; +} diff --git a/mdk-stage1/dietlibc/libpthread/thread_internal.c b/mdk-stage1/dietlibc/libpthread/pthread_internal.c index a93806203..7bb4e16cb 100644 --- a/mdk-stage1/dietlibc/libpthread/thread_internal.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_internal.c @@ -11,14 +11,14 @@ #include <stdio.h> #include "thread_internal.h" -static struct _pthread_fastlock __thread_struct_lock = {0}; +static struct _pthread_fastlock __thread_struct_lock = {PTHREAD_SPIN_UNLOCKED}; static struct _pthread_descr_struct threads[PTHREAD_THREADS_MAX]; static int _max_used_thread_id=1; pthread_once_t __thread_inited; -static struct _pthread_fastlock __manager_thread_signal_lock = {0}; -static struct _pthread_fastlock __manager_thread_data_lock = {1}; -static struct _pthread_fastlock __manager_thread_data_go_lock = {1}; +static struct _pthread_fastlock __manager_thread_signal_lock = {PTHREAD_SPIN_UNLOCKED}; +static struct _pthread_fastlock __manager_thread_data_lock = {PTHREAD_SPIN_LOCKED}; +static struct _pthread_fastlock __manager_thread_data_go_lock = {PTHREAD_SPIN_LOCKED}; //#define DEBUG @@ -70,8 +70,10 @@ _pthread_descr __thread_get_free() for (i=0; i<PTHREAD_THREADS_MAX; i++) { if (threads[i].pid==0) { - threads[i].pid=1; /* mark as taken */ ret = threads+i; + /* clear struct */ + memset(ret,0,sizeof(struct _pthread_descr_struct)); + ret->pid=1; /* mark as taken */ if (i>=_max_used_thread_id) _max_used_thread_id=i+1; break; } @@ -91,22 +93,23 @@ void __thread_wait_some_time() __libc_nanosleep(®,0); } -/* cleanup a thread struct */ -void __thread_cleanup(_pthread_descr th) +/* cleanup/join a thread */ +int __thread_join(_pthread_descr th, void**return_value) { - /* lib provided stack should be freed */ + /* mark thread th as joined */ + if (__testandset(&(th->joined))) return EINVAL; + /* wait for thread to exit */ + while(!th->exited) __thread_wait_some_time(); + /* put return value to caller */ + if (return_value) *return_value=th->retval; + /* cleanup thread */ if (th->stack_begin) free(th->stack_begin); - - /* an other thread has joined this on */ - if (th->joined) { - th->joined->retval=th->retval; - th->joined->join=0; - th->joined=0; - } - th->pid=0; /* mark struct as free */ + th->joined=0; + th->pid=0; + return 0; } -/* SIGHUP handler (thread cnacel) PTHREAD_CANCEL_ASYNCHRONOUS */ +/* SIGHUP handler (thread cancel) PTHREAD_CANCEL_ASYNCHRONOUS */ static void __thread_cancel_handler(int sig) { _pthread_descr this; @@ -144,6 +147,7 @@ static void __kill_all_threads() } } +__attribute__((weak)) volatile void __thread_start__key(int id); __attribute__((weak)) volatile void __thread_start__key(int id) { return; } __attribute__((weak,alias("__thread_start__key"))) volatile void __thread_exit__key(int id); @@ -177,6 +181,14 @@ static void *__mthread_starter(void *arg) #ifdef DEBUG printf("in starter %d, parameter %8p\n", td->pid, td->func); #endif + do { + __thread_wait_some_time(); + if (td->canceled) return (void*)42; + } while (__pthread_trylock(&td->go)); + +#ifdef DEBUG + printf("post starter %d, parameter %8p\n", td->pid, td->func); +#endif if (!td->canceled) { if (!(setjmp(td->jmp_exit))) { @@ -196,13 +208,6 @@ static void *__mthread_starter(void *arg) printf("end starter %d, retval %8p\n", td->pid, td->retval); #endif - /* wake joined thread and put retval */ - if (td->joined) { - td->joined->retval=td->retval; - td->joined->join=0; - td->joined=0; - } - /* execute all functions on the cleanup-stack */ for (i=PTHREAD_MAX_CLEANUP;i;) { if (td->cleanup_stack[--i].func) { @@ -227,7 +232,11 @@ static void __manager_SIGCHLD(int sig) for (i=0; i<_max_used_thread_id; i++) { if (threads[i].pid==pid) { - __thread_cleanup(threads+i); + ++threads[i].exited; + if (threads[i].detached) { + threads[i].joined=0; + __thread_cleanup(threads+i); + } break; } } @@ -255,7 +264,7 @@ static void* __manager_thread(void *arg) while(1) { do { __thread_wait_some_time(); - if (getppid()<0) __manager_SIGTERM(0); + if (getppid()<2) __manager_SIGTERM(0); } while (__pthread_trylock(&__manager_thread_data_lock)); __manager_thread_data->pid = @@ -264,6 +273,8 @@ static void* __manager_thread(void *arg) CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, __manager_thread_data); __thread_wait_some_time(); + __thread_wait_some_time(); + __pthread_unlock(&__manager_thread_data->go); #ifdef DEBUG printf("manager new thread %d\n",__manager_thread_data->pid); #endif @@ -329,7 +340,11 @@ void __thread_init() ++_max_used_thread_id; threads[1].stack_size=sizeof(__manager_thread_stack); +#ifdef __parisc__ + threads[1].stack_addr=__manager_thread_stack; +#else threads[1].stack_addr=&__manager_thread_stack[sizeof(__manager_thread_stack)]; +#endif threads[1].stack_begin=0; threads[1].func=__manager_thread; diff --git a/mdk-stage1/dietlibc/libpthread/pthread_join.c b/mdk-stage1/dietlibc/libpthread/pthread_join.c index 5b295bad1..39c076555 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_join.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_join.c @@ -16,35 +16,24 @@ int pthread_join(pthread_t th, void **thread_return) j=__find_thread_id(th); if (j==-1) { - (*(__errno_location()))=ESRCH; - return -1; + return ESRCH; } thread = __get_thread_struct(j); /* error handling */ if (thread==0) { - (*(__errno_location()))=ESRCH; - return -1; + return ESRCH; } if (this==thread) { - (*(__errno_location()))=EDEADLK; - return -1; + return EDEADLK; } if (thread->detached || thread->joined) { - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } - thread->joined=this; - this->join=1; - - while(this->join) __thread_wait_some_time(); - - if (thread_return) *thread_return=this->retval; - - return 0; + return __thread_join(thread,thread_return); } diff --git a/mdk-stage1/dietlibc/libpthread/thread_key.c b/mdk-stage1/dietlibc/libpthread/pthread_key.c index b0f719fc9..8a77f281a 100644 --- a/mdk-stage1/dietlibc/libpthread/thread_key.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_key.c @@ -7,10 +7,15 @@ struct _pthread_fastlock __thread_keys_lock; struct _thread_key __thread_keys[PTHREAD_KEYS_MAX]; +void __thread_start__key(int id); +void __thread_exit__key(int id); + void __thread_start__key(int id) { int i; + if (id<2) return; + __NO_ASYNC_CANCEL_BEGIN; __pthread_lock(&__thread_keys_lock); @@ -26,8 +31,10 @@ void __thread_exit__key(int id) { int i,try; + if (id<2) return; + __NO_ASYNC_CANCEL_BEGIN; - __pthread_lock(&__thread_keys_lock); +// __pthread_lock(&__thread_keys_lock); for (i=0; i<PTHREAD_KEYS_MAX; i++) { if ((__thread_keys[i].used) && (__thread_keys[i].destructor)) { @@ -36,6 +43,6 @@ void __thread_exit__key(int id) } } - __pthread_unlock(&__thread_keys_lock); +// __pthread_unlock(&__thread_keys_lock); __NO_ASYNC_CANCEL_STOP; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_key_create.c b/mdk-stage1/dietlibc/libpthread/pthread_key_create.c index 44fccea6a..9718c695b 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_key_create.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_key_create.c @@ -1,3 +1,4 @@ +#include <string.h> #include <unistd.h> #include <errno.h> @@ -19,7 +20,7 @@ int pthread_key_create(pthread_key_t *key, void (*destructor)(const void*)) if (!__thread_keys[i].used) { __thread_keys[i].used=1; __thread_keys[i].destructor=destructor; - memset(__thread_keys[i].tkd,0,PTHREAD_THREADS_MAX*sizeof(struct _thread_key)); + memset(__thread_keys[i].tkd,0,PTHREAD_THREADS_MAX*sizeof(void*)); *key=i; ret=0; break; @@ -29,7 +30,7 @@ int pthread_key_create(pthread_key_t *key, void (*destructor)(const void*)) __pthread_unlock(&__thread_keys_lock); __NO_ASYNC_CANCEL_END; - if (ret) (*__errno_location())=EAGAIN; - return ret; + if (ret) return EAGAIN; + return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_key_delete.c b/mdk-stage1/dietlibc/libpthread/pthread_key_delete.c index b1bc366e2..8f7fb577f 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_key_delete.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_key_delete.c @@ -10,8 +10,7 @@ int pthread_key_delete(pthread_key_t key) __THREAD_INIT(); if (key>=PTHREAD_KEYS_MAX) { - (*__errno_location())=EINVAL; - return -1; + return EINVAL; } __thread_keys[key].used=0; diff --git a/mdk-stage1/dietlibc/libpthread/pthread_mutex_destroy.c b/mdk-stage1/dietlibc/libpthread/pthread_mutex_destroy.c index 33a16abd4..f5d66613c 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_mutex_destroy.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_mutex_destroy.c @@ -8,9 +8,8 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex) { __THREAD_INIT(); - if ((mutex->owner)||(mutex->lock.__spinlock)) { - (*(__errno_location()))=EBUSY; - return -1; + if ((mutex->owner)||(mutex->lock.__spinlock==PTHREAD_SPIN_LOCKED)) { + return EBUSY; } return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_mutex_init.c b/mdk-stage1/dietlibc/libpthread/pthread_mutex_init.c index b1797fb20..65161d0ec 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_mutex_init.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_mutex_init.c @@ -1,6 +1,6 @@ #include <unistd.h> #include <errno.h> - +#include <string.h> #include <pthread.h> #include "thread_internal.h" diff --git a/mdk-stage1/dietlibc/libpthread/pthread_mutex_lock.c b/mdk-stage1/dietlibc/libpthread/pthread_mutex_lock.c index 0c3ade9e8..0df2bcd8d 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_mutex_lock.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_mutex_lock.c @@ -15,19 +15,18 @@ int pthread_mutex_lock(pthread_mutex_t *mutex) this = __thread_self(); - if (this!=mutex->owner) { - /* wait for mutex to free */ - __pthread_lock(&(mutex->lock)); - - mutex->owner=this; - } - else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) - { - (*(__errno_location()))=EDEADLK; - return -1; + if (this==mutex->owner) { + if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) + return EDEADLK; + if (mutex->kind==PTHREAD_MUTEX_RECURSIVE_NP) { + ++(mutex->count); + return 0; + } } - if (mutex->kind==PTHREAD_MUTEX_RECURSIVE_NP) ++(mutex->count); + /* wait for mutex to free */ + __pthread_lock(&(mutex->lock)); + mutex->owner=this; return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_mutex_trylock.c b/mdk-stage1/dietlibc/libpthread/pthread_mutex_trylock.c index fcf63f75e..620d26150 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_mutex_trylock.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_mutex_trylock.c @@ -18,16 +18,13 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex) if (this!=mutex->owner) { /* wait for mutex to free */ if (__pthread_trylock(&(mutex->lock))) { - (*(__errno_location()))=EBUSY; - return -1; + return EBUSY; } mutex->owner=this; } - else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) - { - (*(__errno_location()))=EDEADLK; - return -1; + else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) { + return EDEADLK; } if (mutex->kind==PTHREAD_MUTEX_RECURSIVE_NP) ++(mutex->count); diff --git a/mdk-stage1/dietlibc/libpthread/pthread_mutex_unlock.c b/mdk-stage1/dietlibc/libpthread/pthread_mutex_unlock.c index 0b5a1d0f7..0c12282c1 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_mutex_unlock.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_mutex_unlock.c @@ -17,17 +17,14 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex) if (this==mutex->owner) { if (mutex->kind==PTHREAD_MUTEX_RECURSIVE_NP) { - if (--(mutex->count)) - return 0; + if (--(mutex->count)) return 0; } mutex->owner=0; __pthread_unlock(&(mutex->lock)); } - else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) - { - (*(__errno_location()))=EPERM; - return -1; + else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) { + return EPERM; } return 0; diff --git a/mdk-stage1/dietlibc/libpthread/pthread_mutexattr_setkind_np.c b/mdk-stage1/dietlibc/libpthread/pthread_mutexattr_setkind_np.c index ac600f8ed..8b110fe5a 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_mutexattr_setkind_np.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_mutexattr_setkind_np.c @@ -13,6 +13,5 @@ int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind) attr->__mutexkind=kind; return 0; } - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_setcancelstate.c b/mdk-stage1/dietlibc/libpthread/pthread_setcancelstate.c index b906492fb..f832bef70 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_setcancelstate.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_setcancelstate.c @@ -20,6 +20,5 @@ int pthread_setcancelstate(int state, int *oldstate) return 0; } - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_setcanceltype.c b/mdk-stage1/dietlibc/libpthread/pthread_setcanceltype.c index 03d1f53de..f5669b70d 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_setcanceltype.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_setcanceltype.c @@ -20,6 +20,5 @@ int pthread_setcanceltype(int type, int *oldtype) return 0; } - (*(__errno_location()))=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_setschedparam.c b/mdk-stage1/dietlibc/libpthread/pthread_setschedparam.c new file mode 100644 index 000000000..df007c408 --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_setschedparam.c @@ -0,0 +1,21 @@ +#include <unistd.h> +#include <errno.h> + +#include <pthread.h> +#include "thread_internal.h" + +int pthread_setschedparam(pthread_t target_thread, int policy, const struct sched_param *param) +{ + __THREAD_INIT(); + + if (__find_thread_id(target_thread)<0) { + return ESRCH; + } + + if (((policy == SCHED_OTHER) && (param->sched_priority==0)) || + (((policy == SCHED_RR) || (policy == SCHED_FIFO)) && + ((param->sched_priority > 0) && (param->sched_priority <100)))) + return sched_setscheduler(target_thread, policy, param); + + return EINVAL; +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_setspecific.c b/mdk-stage1/dietlibc/libpthread/pthread_setspecific.c index 78339c20b..b66ce31d0 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_setspecific.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_setspecific.c @@ -15,7 +15,6 @@ int pthread_setspecific(pthread_key_t key, const void *value) __thread_keys[key].tkd[id]=value; return 0; } - (*__errno_location())=EINVAL; - return -1; + return EINVAL; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sigmask.c b/mdk-stage1/dietlibc/libpthread/pthread_sigmask.c new file mode 100644 index 000000000..691e9e51a --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_sigmask.c @@ -0,0 +1,8 @@ +#include <signal.h> +#include <errno.h> + +#include <pthread.h> + +int pthread_sigmask(int how, const sigset_t*newset, sigset_t *oldset) { + return (sigprocmask(how,newset,oldset)==-1)?(*(__errno_location())):0; +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_spinlock.c b/mdk-stage1/dietlibc/libpthread/pthread_spinlock.c index 449782adf..463c186bd 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_spinlock.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_spinlock.c @@ -2,12 +2,12 @@ #include <pthread.h> #include "thread_internal.h" -static void __pthread_acquire(int * spinlock) +void __pthread_lock(struct _pthread_fastlock * lock) { int cnt = 0; struct timespec tm; - while (__testandset(spinlock)) { + while (__testandset(&lock->__spinlock)) { if (cnt < MAX_SPIN_COUNT) { sched_yield(); cnt++; @@ -20,11 +20,6 @@ static void __pthread_acquire(int * spinlock) } } -void __pthread_lock(struct _pthread_fastlock * lock) -{ - __pthread_acquire(&lock->__spinlock); -} - int __pthread_trylock(struct _pthread_fastlock * lock) { return __testandset(&lock->__spinlock); @@ -32,7 +27,8 @@ int __pthread_trylock(struct _pthread_fastlock * lock) int __pthread_unlock(struct _pthread_fastlock * lock) { - return (lock->__spinlock = 0); + lock->__spinlock = PTHREAD_SPIN_UNLOCKED; + return 0; } diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sys_alloc.c b/mdk-stage1/dietlibc/libpthread/pthread_sys_alloc.c index 9f7d23d79..9fd4bcd95 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_sys_alloc.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_sys_alloc.c @@ -3,10 +3,11 @@ #include <pthread.h> #include "thread_internal.h" +#include <stdlib.h> + static pthread_mutex_t mutex_alloc = PTHREAD_MUTEX_INITIALIZER; -void free(void *ptr) -{ +void free(void *ptr) { __NO_ASYNC_CANCEL_BEGIN; pthread_mutex_lock(&mutex_alloc); __libc_free(ptr); @@ -14,8 +15,7 @@ void free(void *ptr) __NO_ASYNC_CANCEL_END; } -void *malloc(size_t size) -{ +void *malloc(size_t size) { register void *ret; __NO_ASYNC_CANCEL_BEGIN; pthread_mutex_lock(&mutex_alloc); @@ -24,3 +24,13 @@ void *malloc(size_t size) __NO_ASYNC_CANCEL_END; return ret; } + +void* realloc(void* ptr, size_t size) { + register void *ret; + __NO_ASYNC_CANCEL_BEGIN; + pthread_mutex_lock(&mutex_alloc); + ret=__libc_realloc(ptr, size); + pthread_mutex_unlock(&mutex_alloc); + __NO_ASYNC_CANCEL_END; + return ret; +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sys_fcntl.c b/mdk-stage1/dietlibc/libpthread/pthread_sys_fcntl.c index 99210a488..c7c3fb884 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_sys_fcntl.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_sys_fcntl.c @@ -3,6 +3,7 @@ #include <pthread.h> #include "thread_internal.h" +int fcntl(int fd, int cmd, void *arg); int fcntl(int fd, int cmd, void *arg) { __TEST_CANCEL(); diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sys_fdatasync.c b/mdk-stage1/dietlibc/libpthread/pthread_sys_fdatasync.c new file mode 100644 index 000000000..69857c7b3 --- /dev/null +++ b/mdk-stage1/dietlibc/libpthread/pthread_sys_fdatasync.c @@ -0,0 +1,10 @@ +#include <unistd.h> + +#include <pthread.h> +#include "thread_internal.h" + +int fdatasync(int fd) +{ + __TEST_CANCEL(); + return __libc_fdatasync(fd); +} diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sys_logging.c b/mdk-stage1/dietlibc/libpthread/pthread_sys_logging.c index 6070ad219..f9f93dce2 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_sys_logging.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_sys_logging.c @@ -4,6 +4,8 @@ #include <pthread.h> #include "thread_internal.h" +#include <syslog.h> + static pthread_mutex_t mutex_syslog = PTHREAD_MUTEX_INITIALIZER; void closelog(void) diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sys_open.c b/mdk-stage1/dietlibc/libpthread/pthread_sys_open.c index 513f6a323..8d9fb5523 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_sys_open.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_sys_open.c @@ -3,6 +3,7 @@ #include <pthread.h> #include "thread_internal.h" +int __pthread_open(const char *pathname, int flags, mode_t mode); int __pthread_open(const char *pathname, int flags, mode_t mode) { __TEST_CANCEL(); diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sys_tcdrain.c b/mdk-stage1/dietlibc/libpthread/pthread_sys_tcdrain.c index 1ac33adfc..d5d94978b 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_sys_tcdrain.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_sys_tcdrain.c @@ -3,6 +3,8 @@ #include <pthread.h> #include "thread_internal.h" +#include <termios.h> + int tcdrain(int fd) { __TEST_CANCEL(); diff --git a/mdk-stage1/dietlibc/libpthread/pthread_sys_waitpid.c b/mdk-stage1/dietlibc/libpthread/pthread_sys_waitpid.c index 76d5ddca7..e5020221a 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_sys_waitpid.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_sys_waitpid.c @@ -3,6 +3,8 @@ #include <pthread.h> #include "thread_internal.h" +#include <sys/wait.h> + pid_t waitpid(pid_t pid, int *status, int options) { __TEST_CANCEL(); diff --git a/mdk-stage1/dietlibc/libpthread/pthread_testcancel.c b/mdk-stage1/dietlibc/libpthread/pthread_testcancel.c index 68f91e743..4151faca3 100644 --- a/mdk-stage1/dietlibc/libpthread/pthread_testcancel.c +++ b/mdk-stage1/dietlibc/libpthread/pthread_testcancel.c @@ -10,7 +10,7 @@ void pthread_testcancel() thread=__thread_self(); - if (thread->canceled) { + if (thread && thread->canceled) { pthread_exit(PTHREAD_CANCELED); } } diff --git a/mdk-stage1/dietlibc/libpthread/thread_internal.h b/mdk-stage1/dietlibc/libpthread/thread_internal.h index 5eb3bbd08..7843fb59d 100644 --- a/mdk-stage1/dietlibc/libpthread/thread_internal.h +++ b/mdk-stage1/dietlibc/libpthread/thread_internal.h @@ -9,6 +9,8 @@ #error "the diet libc is not compiled with thread safeness enabled!" #endif +#undef errno + /* cleanup */ #define PTHREAD_MAX_CLEANUP 8 struct thread_cleanup_t { @@ -18,15 +20,13 @@ struct thread_cleanup_t { /* the thread descriptor / internal */ struct _pthread_descr_struct { - /* runtime handling */ - struct _pthread_descr_struct *joined; /* a joined thread or NULL */ - /* conditional variables */ struct _pthread_descr_struct *waitnext; /* an other waiting thread or NULL */ int waiting; /* internal waiting "lock" */ /* thread/process data */ int pid; /* Process id */ + int exited; /* Process is dead */ int policy; /* thread scheduling policy */ int priority; /* thread priority */ @@ -42,7 +42,7 @@ struct _pthread_descr_struct { /* thread exit handling */ void *retval; /* thread return value */ - int join; /* thread waits for other to return */ + int joined; /* flag other thread has joined */ jmp_buf jmp_exit; /* pthread_exit jump */ /* thread flags */ @@ -58,7 +58,7 @@ struct _pthread_descr_struct { void* arg; /* thread argument */ /* create thread / manager thread lock */ - struct _pthread_fastlock *manager_lock; + struct _pthread_fastlock go; /* cleanup stack */ struct thread_cleanup_t cleanup_stack[PTHREAD_MAX_CLEANUP]; @@ -84,12 +84,13 @@ int __clone(void* (*fn)(void*), void* stack, int flags, void *arg); int __find_thread_id(int pid); _pthread_descr __get_thread_struct(int id); -_pthread_descr __thread_get_free(); -_pthread_descr __thread_self(); +_pthread_descr __thread_get_free(void); +_pthread_descr __thread_self(void); -void __thread_cleanup(_pthread_descr th); +int __thread_join(_pthread_descr join, void **return_value); +#define __thread_cleanup(th) (void)__thread_join((th),0) -void __thread_wait_some_time(); +void __thread_wait_some_time(void); #define __NO_ASYNC_CANCEL_BEGIN { int oldtype; pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); #define __NO_ASYNC_CANCEL_END pthread_setcanceltype(oldtype,0); pthread_testcancel(); } @@ -100,7 +101,7 @@ int signal_manager_thread(_pthread_descr td); /* init stuff */ extern pthread_once_t __thread_inited; -void __thread_init(); +void __thread_init(void); #define __THREAD_INIT() __pthread_once(&__thread_inited, __thread_init) #define __TEST_CANCEL() pthread_testcancel() @@ -108,6 +109,7 @@ void __thread_init(); void __libc_free(void *ptr); void *__libc_malloc(size_t size); +void *__libc_realloc(void* ptr, size_t size); void __libc_closelog(void); void __libc_openlog(const char *ident, int option, int facility); @@ -119,6 +121,7 @@ int __libc_close(int fd); int __libc_creat(const char *pathname, mode_t mode); int __libc_fcntl(int fd, int cmd, void *arg); int __libc_fsync(int fd); +int __libc_fdatasync(int fd); int __libc_nanosleep(const struct timespec *req, struct timespec *rem); int __libc_open(const char *pathname, int flags, mode_t mode); int __libc_pause(void); |