source: rtems/cpukit/posix/src/semaphoretranslatereturncode.c @ 6a0898b

4.104.114.95
Last change on this file since 6a0898b was 6a0898b, checked in by Joel Sherrill <joel.sherrill@…>, on 07/18/08 at 18:45:56

2008-07-18 Joel Sherrill <joel.sherrill@…>

PR 1291/cpukit

  • itron/inline/rtems/itron/semaphore.inl, itron/src/twai_sem.c, posix/include/mqueue.h, posix/include/rtems/posix/mqueue.h, posix/include/rtems/posix/semaphore.h, posix/include/rtems/posix/time.h, posix/src/condtimedwait.c, posix/src/mqueuereceive.c, posix/src/mqueuerecvsupp.c, posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/mutextranslatereturncode.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, posix/src/semaphoretranslatereturncode.c, posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c, posix/src/semtrywait.c, posix/src/semwait.c, posix/src/sigtimedwait.c, posix/src/timersettime.c, posix/src/ualarm.c, rtems/src/semobtain.c, rtems/src/semtranslatereturncode.c, score/include/rtems/score/coremutex.h, score/include/rtems/score/coresem.h, score/src/coresemseize.c: This patch addresses issues on implementation of the timeout on the following POSIX services. Some of these services incorrectly took a timeout as a relative time. Others would compute a 0 delta to timeout if the absolute time and the current time were equal and thus incorrectly block the caller forever. The root of the confusion is that POSIX specifies that if the timeout is incorrect (e.g. in the past, is now, or is numerically invalid), that it does not matter if the call would succeed without blocking. This is in contrast to RTEMS programming style where all errors are checked before any critical sections are entered. This fix implemented a more uniform way of handling POSIX absolute time timeouts.

+ pthread_cond_timedwait - could block forever
+ mq_timedreceive - used relative not absolute time
+ mq_timedsend - used relative not absolute time
+ pthread_mutex_timedlock - used relative not absolute time
+ pthread_rwlock_timedrdlock- used relative not absolute time
+ pthread_rwlock_timedwrlock- used relative not absolute time
+ sem_timedwait - could block forever

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 *  POSIX Semaphore Error Translation
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <pthread.h>
19#include <errno.h>
20
21#include <rtems/system.h>
22#include <rtems/score/coresem.h>
23
24/*
25 *  _POSIX_Semaphore_Translate_core_semaphore_return_code
26 *
27 *  Input parameters:
28 *    the_semaphore_status - semaphore status code to translate
29 *
30 *  Output parameters:
31 *    status code - translated POSIX status code
32 *
33 */
34
35static int _POSIX_Semaphore_Return_codes[CORE_SEMAPHORE_STATUS_LAST + 1] = {
36  0,                   /* CORE_SEMAPHORE_STATUS_SUCCESSFUL */
37  EAGAIN,              /* CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT */
38  EAGAIN,              /* CORE_SEMAPHORE_WAS_DELETED */
39  ETIMEDOUT,           /* CORE_SEMAPHORE_TIMEOUT */
40  /* The next error can not occur since we set the maximum
41   * count to the largest value the count can hold.
42   */
43  ENOSYS,              /* CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED */
44};
45
46
47int _POSIX_Semaphore_Translate_core_semaphore_return_code(
48  CORE_semaphore_Status  the_semaphore_status
49)
50{
51  /*
52   *  Internal consistency check for bad status from SuperCore
53   */
54  #if defined(RTEMS_DEBUG)
55    if ( the_semaphore_status > CORE_SEMAPHORE_STATUS_LAST )
56      return EINVAL;
57  #endif
58  return _POSIX_Semaphore_Return_codes[the_semaphore_status];
59}
Note: See TracBrowser for help on using the repository browser.