summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libpthread
diff options
context:
space:
mode:
authorGwenolé Beauchesne <gbeauchesne@mandriva.org>2003-06-04 18:31:57 +0000
committerGwenolé Beauchesne <gbeauchesne@mandriva.org>2003-06-04 18:31:57 +0000
commit09e967c2d732783b2579e4e120cd9b608404cb00 (patch)
tree8d2783a6a7e33608c6012efd6a88b8f5694df81d /mdk-stage1/dietlibc/libpthread
parent18fcff49d3c836697d3b75a3d01d31c700e69974 (diff)
downloaddrakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.gz
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.bz2
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.xz
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.zip
Merge from R9_0-AMD64, most notably:
- AMD64 support to insmod-busybox, minilibc, et al. - Sync with insmod-modutils 2.4.19 something but everyone should use dietlibc nowadays - Factor out compilation and prefix with $(DIET) for dietlibc builds - 64-bit & varargs fixes
Diffstat (limited to 'mdk-stage1/dietlibc/libpthread')
-rw-r--r--mdk-stage1/dietlibc/libpthread/CHANGES6
-rw-r--r--mdk-stage1/dietlibc/libpthread/Makefile7
-rw-r--r--mdk-stage1/dietlibc/libpthread/README10
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_atfork.c2
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_attr_init.c1
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_attr_setdetachstate.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_attr_setinheritsched.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_attr_setschedparam.c5
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_attr_setschedpolicy.c5
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_attr_setscope.c5
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_attr_setstacksize.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_cancel.c6
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_cond_broadcast.c9
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_cond_destroy.c4
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_cond_init.c1
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_cond_signal.c2
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_cond_timedwait.c51
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_cond_wait.c26
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_create.c27
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_detach.c11
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_join.c21
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_key_create.c7
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_key_delete.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_mutex_destroy.c5
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_mutex_init.c2
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_mutex_lock.c21
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_mutex_trylock.c9
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_mutex_unlock.c9
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_mutexattr_setkind_np.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_setcancelstate.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_setcanceltype.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_setspecific.c3
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_spinlock.c12
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_sys_alloc.c18
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_sys_fcntl.c1
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_sys_logging.c2
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_sys_open.c1
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_sys_tcdrain.c2
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_sys_waitpid.c2
-rw-r--r--mdk-stage1/dietlibc/libpthread/pthread_testcancel.c2
-rw-r--r--mdk-stage1/dietlibc/libpthread/thread_internal.h23
41 files changed, 192 insertions, 147 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.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);