public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Graves, Daniel (GE Healthcare)" <Daniel.Graves@ge.com>
To: <ecos-discuss@sourceware.org>
Subject: [ECOS] Help with pthread_cond_timedwait
Date: Tue, 15 May 2012 15:34:00 -0000	[thread overview]
Message-ID: <6F6D3EC964AAC24D9C45644424DE2D810BDF568B@CINMLVEM19.e2k.ad.ge.com> (raw)

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

             reply	other threads:[~2012-05-15 15:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-15 15:34 Graves, Daniel (GE Healthcare) [this message]
2012-05-15 19:06 ` Christophe Coutand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6F6D3EC964AAC24D9C45644424DE2D810BDF568B@CINMLVEM19.e2k.ad.ge.com \
    --to=daniel.graves@ge.com \
    --cc=ecos-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).