123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "pthread.h"
- #include "semaphore.h"
- #include "implement.h"
- int pte_cancellable_wait (pte_osSemaphoreHandle semHandle, unsigned int* timeout)
- {
- int result = EINVAL;
- pte_osResult osResult;
- int cancelEnabled = 0;
- pthread_t self;
- pte_thread_t * sp;
- self = pthread_self();
- sp = (pte_thread_t *) self.p;
- if (sp != NULL)
- {
-
- if (sp->cancelState == PTHREAD_CANCEL_ENABLE)
- {
- cancelEnabled = 1;
- }
- }
- if (cancelEnabled)
- {
- osResult = pte_osSemaphoreCancellablePend(semHandle, timeout);
- }
- else
- {
- osResult = pte_osSemaphorePend(semHandle, timeout);
- }
- switch (osResult)
- {
- case PTE_OS_OK:
- {
- result = 0;
- break;
- }
- case PTE_OS_TIMEOUT:
- {
- result = ETIMEDOUT;
- break;
- }
- case PTE_OS_INTERRUPTED:
- {
- if (sp != NULL)
- {
-
- (void) pthread_mutex_lock (&sp->cancelLock);
- if (sp->state < PThreadStateCanceling)
- {
- sp->state = PThreadStateCanceling;
- sp->cancelState = PTHREAD_CANCEL_DISABLE;
- (void) pthread_mutex_unlock (&sp->cancelLock);
- pte_throw (PTE_EPS_CANCEL);
-
- }
- (void) pthread_mutex_unlock (&sp->cancelLock);
- }
- break;
- }
- default:
- {
- result = EINVAL;
- }
- }
- return (result);
- }
|