diff options
author | Mystery Man <unknown@mandriva.org> | 2003-10-29 16:07:11 +0000 |
---|---|---|
committer | Mystery Man <unknown@mandriva.org> | 2003-10-29 16:07:11 +0000 |
commit | fa40f30b4253b1e05c46cc5e0c111176825b7623 (patch) | |
tree | 76cf2d26c0ce0ee7c6a2c1a1a2b65bc4d8e33029 /mdk-stage1/dietlibc/libpthread | |
parent | 327bd24f8e4291bd1882de1990dd7339f781a9cb (diff) | |
download | drakx-Corpo_2_1_1.tar drakx-Corpo_2_1_1.tar.gz drakx-Corpo_2_1_1.tar.bz2 drakx-Corpo_2_1_1.tar.xz drakx-Corpo_2_1_1.zip |
This commit was manufactured by cvs2svn to create tag 'Corpo_2_1_1'.Corpo_2_1_1
Diffstat (limited to 'mdk-stage1/dietlibc/libpthread')
43 files changed, 192 insertions, 532 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_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/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_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_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_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.c b/mdk-stage1/dietlibc/libpthread/thread_internal.c deleted file mode 100644 index a93806203..000000000 --- a/mdk-stage1/dietlibc/libpthread/thread_internal.c +++ /dev/null @@ -1,344 +0,0 @@ -#include <signal.h> -#include <string.h> -#include <sys/wait.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> - -#include <sched.h> -#include <sys/resource.h> - -#include <stdio.h> -#include "thread_internal.h" - -static struct _pthread_fastlock __thread_struct_lock = {0}; -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}; - -//#define DEBUG - -/* find thread */ -int __find_thread_id(int pid) -{ - register int i; - for (i=0; i<_max_used_thread_id; i++) - if (threads[i].pid==pid) - return i; - return -1; -} - -/* get thread */ -_pthread_descr __get_thread_struct(int id) -{ - return threads+id; -} - -/* thread errno location */ -int *__errno_location(void) -{ - int id=0; - if (__thread_inited) id=__find_thread_id(getpid()); - if (id<0) - return 0; - else - return &threads[id].errno; -} - -/* thread self */ -_pthread_descr __thread_self() -{ - register int i=__find_thread_id(getpid()); - if (i<0) - return 0; - else - return threads+i; -} - -/* allocate a thread slot */ -_pthread_descr __thread_get_free() -{ - _pthread_descr ret=0; - int i; - - __NO_ASYNC_CANCEL_BEGIN; - __pthread_lock(&__thread_struct_lock); - - for (i=0; i<PTHREAD_THREADS_MAX; i++) { - if (threads[i].pid==0) { - threads[i].pid=1; /* mark as taken */ - ret = threads+i; - if (i>=_max_used_thread_id) _max_used_thread_id=i+1; - break; - } - } - - __pthread_unlock(&__thread_struct_lock); - __NO_ASYNC_CANCEL_END; - return ret; -} - -/* sleep a little (reschedule for this time) */ -void __thread_wait_some_time() -{ - struct timespec reg; - reg.tv_sec=0; - reg.tv_nsec=SPIN_SLEEP_DURATION; - __libc_nanosleep(®,0); -} - -/* cleanup a thread struct */ -void __thread_cleanup(_pthread_descr th) -{ - /* lib provided stack should be freed */ - 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 */ -} - -/* SIGHUP handler (thread cnacel) PTHREAD_CANCEL_ASYNCHRONOUS */ -static void __thread_cancel_handler(int sig) -{ - _pthread_descr this; - this = __thread_self(); - this->canceled=1; - if (this->canceltype==PTHREAD_CANCEL_ASYNCHRONOUS) - pthread_exit(PTHREAD_CANCELED); - signal( SIGHUP, __thread_cancel_handler ); -} - -/* kill ALL threads / other then prime task and manager thread */ -static void __kill_all_threads() -{ - int i; - - for (i=2; i<_max_used_thread_id; i++) { - if (threads[i].pid>1) { -#ifdef DEBUG - printf("CANCEL ! %d\n",threads[i].pid); -#endif - threads[i].canceled=1; - kill(threads[i].pid, SIGHUP); /* cancel thread */ - } - } - - __thread_wait_some_time(); - - for (i=2; i<_max_used_thread_id; i++) { - if (threads[i].pid>1) { -#ifdef DEBUG - printf("KILL ! %d\n",threads[i].pid); -#endif - kill(threads[i].pid, SIGTERM); /* KILL thread */ - } - } -} - -__attribute__((weak)) volatile void __thread_start__key(int id) { return; } -__attribute__((weak,alias("__thread_start__key"))) volatile void __thread_exit__key(int id); - -/* support for manager */ -static void *__mthread_starter(void *arg) -{ - _pthread_descr td = (_pthread_descr)arg; - int i = td->stack_size-4096; - - /* just to be sure */ - td->pid=getpid(); - - /* signal handling for a thread */ - signal(SIGTERM, _exit); - signal(SIGCHLD, SIG_DFL); - signal(SIGHUP, __thread_cancel_handler ); - - /* limit stack so that we NEVER have to worry */ - setrlimit(RLIMIT_STACK, (struct rlimit *)(&i)); - - /* set scheduler */ - if (td->policy!=SCHED_OTHER) { - struct sched_param sp; - sp.sched_priority=td->priority; - sched_setscheduler(td->pid,td->policy, &sp); - } - - /* thread_key glue */ - __thread_start__key(td-threads); - -#ifdef DEBUG - printf("in starter %d, parameter %8p\n", td->pid, td->func); -#endif - - if (!td->canceled) { - if (!(setjmp(td->jmp_exit))) { - td->retval=td->func(td->arg); -#ifdef DEBUG - } else { - printf("pthread_exit called in %d\n", td->pid); -#endif - } - } - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,0); - - /* thread_key glue */ - __thread_exit__key(td-threads); - -#ifdef DEBUG - 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) { - td->cleanup_stack[i].func(td->cleanup_stack[i].arg); - } - } - - return 0; -} - - -/* manager thread and signal handler */ -static char __manager_thread_stack[12*1024]; -static volatile _pthread_descr __manager_thread_data; -static void __manager_SIGCHLD(int sig) -{ - int pid, status, i; - - while(1) { - pid = __libc_waitpid (-1, &status, WNOHANG); - if (pid <= 0) break; - - for (i=0; i<_max_used_thread_id; i++) { - if (threads[i].pid==pid) { - __thread_cleanup(threads+i); - break; - } - } - } -} - -static void __manager_SIGTERM(int sig) -{ - __kill_all_threads(); - _exit(0); -} - -static void* __manager_thread(void *arg) -{ - struct sigaction sig_action_chld; - sig_action_chld.sa_handler = __manager_SIGCHLD; - sigemptyset(&sig_action_chld.sa_mask); - sig_action_chld.sa_flags = SA_RESTART; - - sigaction(SIGCHLD, &sig_action_chld, 0); - signal(SIGTERM, __manager_SIGTERM); - signal(SIGHUP, SIG_IGN); - - __pthread_unlock(&__manager_thread_data_go_lock); /* release init */ - while(1) { - do { - __thread_wait_some_time(); - if (getppid()<0) __manager_SIGTERM(0); - } while (__pthread_trylock(&__manager_thread_data_lock)); - - __manager_thread_data->pid = - __clone(__mthread_starter, - __manager_thread_data->stack_addr, - CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, - __manager_thread_data); - __thread_wait_some_time(); -#ifdef DEBUG - printf("manager new thread %d\n",__manager_thread_data->pid); -#endif - __pthread_unlock(&__manager_thread_data_go_lock); /* release sender */ - } - return 0; -} - -/* pthread_create bottom half */ -int signal_manager_thread(_pthread_descr td) -{ - __NO_ASYNC_CANCEL_BEGIN; - - __pthread_lock(&__manager_thread_signal_lock); /* lock */ - - __manager_thread_data = td; - __thread_wait_some_time(); - __pthread_unlock(&__manager_thread_data_lock); /* signal manager to start */ - __thread_wait_some_time(); - __pthread_lock(&__manager_thread_data_go_lock); /* wait for manager */ - - __pthread_unlock(&__manager_thread_signal_lock); /* unlock */ - - __NO_ASYNC_CANCEL_END; - - return td->pid; -} - - -/* thread stop */ -static void __thread_main_exit() -{ - if (getpid()!=threads[0].pid) { -#ifdef DEBUG - printf("A THREAD ? %d\n",getpid()); -#endif - kill(threads[0].pid, SIGTERM); - while(1) __thread_wait_some_time(); - } -#ifdef DEBUG - else - printf("EXIT ! %d\n",getpid()); -#endif - - /* stop ALL threads */ - kill(threads[1].pid, SIGTERM); - __thread_wait_some_time(); - __kill_all_threads(); -} - -/* thread intern init */ -void __thread_init() -{ - if (atexit(__thread_main_exit)==-1) - exit(42); - -#ifdef DEBUG - printf("INIT ! %d\n",getpid()); - memset(threads,0,sizeof(threads)); -#endif - - threads[0].pid = getpid(); - - ++_max_used_thread_id; - threads[1].stack_size=sizeof(__manager_thread_stack); - threads[1].stack_addr=&__manager_thread_stack[sizeof(__manager_thread_stack)]; - threads[1].stack_begin=0; - threads[1].func=__manager_thread; - - threads[1].pid = __clone(__mthread_starter, threads[1].stack_addr, - CLONE_VM | CLONE_FS | CLONE_FILES, threads+1); - -#ifdef DEBUG - printf("manager thread @ : %d\n",threads[1].pid); -#endif - __pthread_lock(&__manager_thread_data_go_lock); /* wait for manager to be ready */ -} - 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); diff --git a/mdk-stage1/dietlibc/libpthread/thread_key.c b/mdk-stage1/dietlibc/libpthread/thread_key.c deleted file mode 100644 index b0f719fc9..000000000 --- a/mdk-stage1/dietlibc/libpthread/thread_key.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <unistd.h> -#include <errno.h> - -#include <pthread.h> -#include "thread_internal.h" - -struct _pthread_fastlock __thread_keys_lock; -struct _thread_key __thread_keys[PTHREAD_KEYS_MAX]; - -void __thread_start__key(int id) -{ - int i; - - __NO_ASYNC_CANCEL_BEGIN; - __pthread_lock(&__thread_keys_lock); - - for (i=0; i<PTHREAD_KEYS_MAX; i++) { - __thread_keys[i].tkd[id]=0; - } - - __pthread_unlock(&__thread_keys_lock); - __NO_ASYNC_CANCEL_END; -} - -void __thread_exit__key(int id) -{ - int i,try; - - __NO_ASYNC_CANCEL_BEGIN; - __pthread_lock(&__thread_keys_lock); - - for (i=0; i<PTHREAD_KEYS_MAX; i++) { - if ((__thread_keys[i].used) && (__thread_keys[i].destructor)) { - for (try=0;__thread_keys[i].tkd[id] && (try<PTHREAD_DESTRUCTOR_ITERATIONS);++try) - __thread_keys[i].destructor(__thread_keys[i].tkd[id]); - } - } - - __pthread_unlock(&__thread_keys_lock); - __NO_ASYNC_CANCEL_STOP; -} |