Ticket #841: timedwait.diffs

File timedwait.diffs, 1.5 KB (added by dufault, on 12/03/06 at 13:31:13)

timedwait.diffs

Line 
1Index: semtimedwait.c
2===================================================================
3RCS file: /usr1/CVS/rtems/cpukit/posix/src/semtimedwait.c,v
4retrieving revision 1.4
5diff -u -r1.4 semtimedwait.c
6--- semtimedwait.c      1 Sep 2005 14:44:04 -0000       1.4
7+++ semtimedwait.c      2 Nov 2005 19:28:35 -0000
8@@ -40,24 +40,30 @@
9   struct timespec   difference;
10 
11   /*
12-   *  Error check the absolute time to timeout
13+   * POSIX says:
14+   * "Under no circumstance shall the function fail with a timeout if the
15+   * semaphore can be locked immediately."  It also mentions it doesn't even
16+   * need to be checked.
17+   */
18+  if (sem_trywait(sem) == 0)
19+    return 0;
20+
21+  /*
22+   *  Error check the absolute time to timeout.
23    */
24-  if ( /* abstime->tv_sec < 0 || */ abstime->tv_nsec ) /* tv_sec is unsigned */
25-    return EINVAL;
26 
27   if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
28-    return EINVAL;
29+      rtems_set_errno_and_return_minus_one( EINVAL );
30   
31   (void) clock_gettime( CLOCK_REALTIME, &current_time );
32 
33   /*
34    *  Make sure the abstime is in the future
35    */
36-  if ( abstime->tv_sec < current_time.tv_sec )
37-    return EINVAL;
38-  if ( (abstime->tv_sec == current_time.tv_sec) &&
39-       (abstime->tv_nsec <= current_time.tv_nsec) )
40-    return EINVAL;
41+  if ( abstime->tv_sec < current_time.tv_sec ||
42+  ((abstime->tv_sec == current_time.tv_sec) &&
43+   (abstime->tv_nsec <= current_time.tv_nsec)) )
44+      rtems_set_errno_and_return_minus_one( ETIMEDOUT );
45 
46   _POSIX_Timespec_subtract( &current_time, abstime, &difference );
47