123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #include <stdio.h>
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_delay_np (struct timespec *interval)
- {
- unsigned int wait_time;
- unsigned int secs_in_millisecs;
- unsigned int millisecs;
- pthread_t self;
- pte_thread_t * sp;
- if (interval == NULL)
- {
- return EINVAL;
- }
- if (interval->tv_sec == 0L && interval->tv_nsec == 0L)
- {
- pthread_testcancel ();
- pte_osThreadSleep (1);
- pthread_testcancel ();
- return (0);
- }
-
- secs_in_millisecs = interval->tv_sec * 1000L;
-
- millisecs = (interval->tv_nsec + 999999L) / 1000000L;
- wait_time = secs_in_millisecs + millisecs;
- if (NULL == (self = pthread_self ()))
- {
- return ENOMEM;
- }
- sp = (pte_thread_t *) self;
- if (sp->cancelState == PTHREAD_CANCEL_ENABLE)
- {
- pte_osResult cancelStatus;
-
- cancelStatus = pte_osThreadCheckCancel(sp->threadId);
- if (cancelStatus == PTE_OS_INTERRUPTED)
- {
-
- (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);
- return ESRCH;
- }
- else if (cancelStatus != PTE_OS_OK)
- {
- return EINVAL;
- }
- }
- else
- {
- pte_osThreadSleep (wait_time);
- }
- return (0);
- }
|