|
@@ -46,9 +46,9 @@ int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex
|
|
|
int pthread_mutex_lock (pthread_mutex_t *mutex)
|
|
|
{
|
|
|
while (mutex->__m_lock.__spinlock == 0) {
|
|
|
- usleep(10000);
|
|
|
- }
|
|
|
- --(mutex->__m_lock.__spinlock);
|
|
|
+ usleep(10000);
|
|
|
+ }
|
|
|
+ --(mutex->__m_lock.__spinlock);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -60,11 +60,11 @@ int pthread_mutex_unlock (pthread_mutex_t *mutex)
|
|
|
|
|
|
int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
|
|
|
{
|
|
|
- ++(mutex->__m_lock.__spinlock);
|
|
|
- while (cond->__c_lock.__spinlock == 0) {
|
|
|
- usleep(10000);
|
|
|
- }
|
|
|
- --(cond->__c_lock.__spinlock);
|
|
|
+ ++(mutex->__m_lock.__spinlock);
|
|
|
+ while (cond->__c_lock.__spinlock == 0) {
|
|
|
+ usleep(10000);
|
|
|
+ }
|
|
|
+ --(cond->__c_lock.__spinlock);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -82,25 +82,40 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
|
|
|
|
|
|
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void* (*fn)(void *), void *data)
|
|
|
{
|
|
|
- long retval;
|
|
|
- void **newstack;
|
|
|
+ long retval;
|
|
|
+ void **newstack;
|
|
|
int (*clonefunc)(void *) = (int (*)(void *))(fn);
|
|
|
|
|
|
- newstack = (void **) malloc(STACKSIZE);
|
|
|
- if (!newstack)
|
|
|
- return -1;
|
|
|
- newstack = (void **) (STACKSIZE + (char *) newstack);
|
|
|
- *--newstack = data;
|
|
|
- retval = clone(clonefunc, newstack,
|
|
|
+ newstack = (void **) malloc(STACKSIZE);
|
|
|
+ if (!newstack)
|
|
|
+ return -1;
|
|
|
+ newstack = (void **) (STACKSIZE + (char *) newstack);
|
|
|
+ *--newstack = data;
|
|
|
+ retval = clone(clonefunc, newstack,
|
|
|
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD, data);
|
|
|
- if (retval < 0) {
|
|
|
- errno = -retval;
|
|
|
- *thread = 0;
|
|
|
- retval = -1;
|
|
|
- } else {
|
|
|
- *thread = retval;
|
|
|
- retval = 0;
|
|
|
- }
|
|
|
- return retval;
|
|
|
+ if (retval < 0) {
|
|
|
+ errno = -retval;
|
|
|
+ *thread = 0;
|
|
|
+ retval = -1;
|
|
|
+ } else {
|
|
|
+ *thread = retval;
|
|
|
+ retval = 0;
|
|
|
+ }
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+int pthread_join (pthread_t thread, void **thread_return)
|
|
|
+{
|
|
|
+ int retval;
|
|
|
+
|
|
|
+ retval = EXIT_SUCCESS;
|
|
|
+ if (thread_return)
|
|
|
+ *thread_return = retval;
|
|
|
+ _exit(retval);
|
|
|
}
|
|
|
+link_warning(pthread_join, "pthread_join is a stub and does not behave properly");
|
|
|
|
|
|
+void pthread_exit (void *retval)
|
|
|
+{
|
|
|
+ _exit(retval);
|
|
|
+}
|