lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Re:use of struct timeval in sys_jiffies, UNIX port


From: R. D. Flowers, Chattanooga TN USA
Subject: [lwip-users] Re:use of struct timeval in sys_jiffies, UNIX port
Date: Fri, 20 Jun 2008 20:16:26 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060501 Fedora/1.7.13-1.1.fc4

Date: Thu, 19 Jun 2008 16:37:30 +0200
From: address@hidden
Subject: [lwip-users] use of struct timeval in sys_jiffies, UNIX port
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain;       charset=ISO-8859-1;     DelSp="Yes";
        format="flowed"

My compiler complained about tv.tv_sec being used before it was
initialized, and upon inspection I must say I don't really understand
what is happening.

Depending on the compiler, isn't the value of tv_sec at best
initialized to zero, otherwise unpredictable? And the result from gettimeofday is not used for anything?

  From sys_arch.c, UNIX port, latest version in CVS.

unsigned long
sys_jiffies(void)
{
      struct timeval tv;
      unsigned long sec = tv.tv_sec;
      long usec = tv.tv_usec;

      gettimeofday(&tv,NULL);

Unless it has changed from the documentation and from what's obvious, it IS exactly the call to gettimeofday that stuffs tv and all its members.

You are trying to use one of those members to initialize usec before tv is defined.

What am I missing ?


      if (sec >= (MAX_JIFFY_OFFSET / HZ))
        return MAX_JIFFY_OFFSET;
      usec += 1000000L / HZ - 1;
      usec /= 1000000L / HZ;
      return HZ * sec + usec;
}

Index: sys_arch.c
===================================================================
RCS file: /sources/lwip/contrib/ports/unix/sys_arch.c,v
retrieving revision 1.21
diff -u -5 -p -r1.21 sys_arch.c
--- sys_arch.c  30 May 2008 11:41:51 -0000      1.21
+++ sys_arch.c  19 Jun 2008 15:29:50 -0000
@@ -585,14 +585,16 @@ sys_arch_unprotect(sys_prot_t pval)

 unsigned long
 sys_jiffies(void)
 {
     struct timeval tv;
-    unsigned long sec = tv.tv_sec;
-    long usec = tv.tv_usec;
+    unsigned long sec;
+    long usec;

Yes. Declared here. Defined later.


     gettimeofday(&tv,NULL);
+    sec = tv.tv_sec - starttime.tv_sec;
+    usec = tv.tv_usec;

     if (sec >= (MAX_JIFFY_OFFSET / HZ))
        return MAX_JIFFY_OFFSET;
     usec += 1000000L / HZ - 1;
     usec /= 1000000L / HZ;







reply via email to

[Prev in Thread] Current Thread [Next in Thread]