123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- #include <pte_osal.h>
- #include "pthread.h"
- #include "implement.h"
- #include <stdio.h>
- int
- pthread_join (pthread_t thread, void **value_ptr)
- {
- int result;
- pthread_t self;
- pte_thread_t * tp = (pte_thread_t *) thread.p;
- pte_osMutexLock (pte_thread_reuse_lock);
- if (NULL == tp
- || thread.x != tp->ptHandle.x)
- {
- result = ESRCH;
- }
- else if (PTHREAD_CREATE_DETACHED == tp->detachState)
- {
- result = EINVAL;
- }
- else
- {
- result = 0;
- }
- pte_osMutexUnlock(pte_thread_reuse_lock);
- if (result == 0)
- {
-
- self = pthread_self();
- if (NULL == self.p)
- {
- result = ENOENT;
- }
- else if (pthread_equal (self, thread))
- {
- result = EDEADLK;
- }
- else
- {
-
- result = pte_osThreadWaitForEnd(tp->threadId);
- if (PTE_OS_OK == result)
- {
- if (value_ptr != NULL)
- {
- *value_ptr = tp->exitStatus;
- }
-
- result = pthread_detach (thread);
- }
- else if (result == PTE_OS_INTERRUPTED)
- {
-
- result = 0;
- }
- else
- {
- result = ESRCH;
- }
- }
- }
- return (result);
- }
|