[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug on getTimeout()
From: |
fedagostino |
Subject: |
bug on getTimeout() |
Date: |
9 Dec 2003 08:08:20 -0000 |
I'm using common cpp on dec alpha processor with unix system.
Mi application go up to 100% of cpu usage and i found that event::wait does not
work correctly.
timespec *getTimeout(struct timespec *spec, timeout_t timer)
{
static struct timespec myspec;
if(spec == NULL)
spec = &myspec;
#ifdef PTHREAD_GET_EXPIRATION_NP
struct timespec offset;
offset.tv_sec = timer / 1000;
offset.tv_nsec = (timer % 1000) * 1000000;
pthread_get_expiration_np(&offset, sec);
#else
struct timeval current;
gettimeofday(¤t, NULL);
spec->tv_sec = current.tv_sec + timer / 1000;
spec->tv_nsec = (current.tv_usec + (timer % 1000) * 1000) * 1000;
#endif
return spec;
}
changhe it to
timespec *getTimeout(struct timespec *spec, timeout_t timer)
{
static struct timespec myspec;
if(spec == NULL)
spec = &myspec;
#ifdef PTHREAD_GET_EXPIRATION_NP
struct timespec offset;
offset.tv_sec = timer / 1000;
offset.tv_nsec = (timer % 1000) * 1000000;
pthread_get_expiration_np(&offset, sec);
#else
struct timeval current;
gettimeofday(¤t, NULL);
spec->tv_sec = current.tv_sec + timer / 1000;
spec->tv_nsec = (current.tv_usec + (timer % 1000) * 1000) * 1000;
while (spec->tv_nsec >=1000000000)
{
spec->tv_nsec -= 1000000000;
spec->tv_sec += 1;
}
#endif
return spec;
}
i have added while loop this prevent pthread_cond_timedwait function to exit
with EINVAL value.
thanks for attention and excuse me for my english.
---------------------------------------------------------
Stanco dello spam nella tua email? Prova GRATIS
il nuovo servizio ANTISPAM di superEva:
http://webmail.supereva.it/spam.html
---------------------------------------------------------
- bug on getTimeout(),
fedagostino <=