123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #include "pthread.h"
- #include "implement.h"
- #include <stdio.h>
- int
- pthread_cancel (pthread_t thread)
- {
- int result;
- int cancel_self;
- pthread_t self;
- pte_thread_t * tp;
- result = pthread_kill (thread, 0);
- if (0 != result)
- {
- return result;
- }
- if ((self = pthread_self ()).p == NULL)
- {
- return ENOMEM;
- };
-
- cancel_self = pthread_equal (thread, self);
- tp = (pte_thread_t *) thread.p;
-
- (void) pthread_mutex_lock (&tp->cancelLock);
- if (tp->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
- && tp->cancelState == PTHREAD_CANCEL_ENABLE
- && tp->state < PThreadStateCanceling)
- {
- if (cancel_self)
- {
- tp->state = PThreadStateCanceling;
- tp->cancelState = PTHREAD_CANCEL_DISABLE;
- (void) pthread_mutex_unlock (&tp->cancelLock);
- pte_throw (PTE_EPS_CANCEL);
-
- }
- else
- {
-
- (void) pthread_mutex_unlock (&tp->cancelLock);
- result = EPERM;
- }
- }
- else
- {
-
- if (tp->state < PThreadStateCancelPending)
- {
- tp->state = PThreadStateCancelPending;
- if (pte_osThreadCancel(tp->threadId) != PTE_OS_OK)
- {
- result = ESRCH;
- }
- }
- else if (tp->state >= PThreadStateCanceling)
- {
- result = ESRCH;
- }
- (void) pthread_mutex_unlock (&tp->cancelLock);
- }
- return (result);
- }
|