123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #include <pte_osal.h>
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_detach (pthread_t thread)
- {
- int result;
- unsigned char destroyIt = PTE_FALSE;
- 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;
- if (pthread_mutex_lock (&tp->cancelLock) == 0)
- {
- if (tp->state != PThreadStateLast)
- {
- tp->detachState = PTHREAD_CREATE_DETACHED;
- }
- else if (tp->detachState != PTHREAD_CREATE_DETACHED)
- {
-
- destroyIt = PTE_TRUE;
- }
- (void) pthread_mutex_unlock (&tp->cancelLock);
- }
- else
- {
-
- result = ESRCH;
- }
- }
- pte_osMutexUnlock(pte_thread_reuse_lock);
- if (result == 0)
- {
-
- if (destroyIt)
- {
-
- pte_osThreadWaitForEnd(tp->threadId);
- pte_threadDestroy (thread);
- }
- }
- return (result);
- }
|