You can possibly log the current time (cyg_current_time()) in 
pthread_cond_timedwait() before the call to:

((Cyg_Condition_Variable *)cond)->wait( *(Cyg_Mutex *)mutex, ticks );

and compare with the ticks value, that way you can rule out any issue with the 
time/ticks conversion.

Christophe

-----Original Message-----
From: ecos-discuss-ow...@ecos.sourceware.org 
[mailto:ecos-discuss-ow...@ecos.sourceware.org] On Behalf Of Graves, Daniel (GE 
Healthcare)
Sent: 15. mai 2012 17:34
To: ecos-disc...@sourceware.org
Subject: [ECOS] Help with pthread_cond_timedwait

Hello,

I've been developing some communication software that needs to wait for a 
message over a serial port.  I implemented it using pthread_cond_timedwait 
under Linux using 2.6.34 kernel.  Basically when a message comes over the 
serial port the pthread_cond_timedwait is signaled.  It waits for 200ms if it 
is not signaled in time.  This code has worked really well in Linux, but I 
needed to port it over to eCos.  At that point the exact same code would 
timeout immediately even though the serial messages were signaling it on time.  
The error 360 for ETIMEDOUT was reporting and it was clear that it wasn't 
waiting long enough.  As a last desperate attempt to get this to work I changed 
the code to use cyg_cond_timed_wait and cyg_cond_mutex from eCos.  That worked 
for me and timeouts were no longer occurring.  However, I would like to know 
what is wrong with pthread_cond_timedwait, because it seems like there is a 
bug.  But after looking at the code for each function they both basically end 
up calling Cyg_Condition_Variable's wait methods.  Below is a snippet of the 
code I'm referring to.  I've searched through this mailing list for any similar 
topics.  There was one but that one focused on clock_gettime.  Unfortunately I 
do not know which version of eCos I'm using as I have just joined the project 
where we're using eCos.  I will try to find that out.

.....
  struct timespec waittime;
  struct timeval abstime;
.....

    gettimeofday(&abstime,NULL);
   //we want to wait 200 msec before declaring timeout
    abstime.tv_usec += 2000000;

    if(abstime.tv_usec >= 1000000)
    {
      abstime.tv_sec += 1;
      abstime.tv_usec = abstime.tv_usec % 1000000;
    }
    waittime.tv_sec = abstime.tv_sec;
    waittime.tv_nsec = abstime.tv_usec*1000;
    int cond_result = pthread_cond_timedwait(&ackcond,&readlock,&waittime);
    if ( cond_result != 0 )
    {
        printf("SerialComm:Failed to set the conditional variable, error = 
%d\n", cond_result);
    }
    else
    {
        #if DEBUG
        printf("SerialComm:Successfully set conditional variable ackcond\n");
        #endif
    }

......

Thanks,

Daniel P Graves


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply via email to