source: rtems/cpukit/itron/inline/rtems/itron/semaphore.inl @ a2cf229

4.8
Last change on this file since a2cf229 was a2cf229, checked in by Joel Sherrill <joel.sherrill@…>, on 07/22/08 at 17:17:12

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: 4.5 KB
Line 
1/**
2 * @file rtems/itron/semaphore.inl
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#ifndef _RTEMS_ITRON_SEMAPHORE_INL
17#define _RTEMS_ITRON_SEMAPHORE_INL
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/*
24 *  _ITRON_Semaphore_Allocate
25 *
26 *  DESCRIPTION:
27 *
28 *  This routine allocates the semaphore associated with the specified
29 *  semaphore ID from the pool of inactive semaphores.
30 *
31 *  Input parameters:
32 *    semid   - id of semaphore to allocate
33 *    status  - pointer to status variable
34 *
35 *  Output parameters:
36 *    returns - pointer to the semaphore control block
37 *    *status - status
38 */
39
40RTEMS_INLINE_ROUTINE ITRON_Semaphore_Control *_ITRON_Semaphore_Allocate(
41  ID   semid
42)
43{
44  return (ITRON_Semaphore_Control *)_ITRON_Objects_Allocate_by_index(
45    &_ITRON_Semaphore_Information,
46    semid,
47    sizeof(ITRON_Semaphore_Control)
48  );
49}
50
51/*
52 *  _ITRON_Semaphore_Clarify_allocation_id_error
53 *
54 *  This function is invoked when an object allocation ID error
55 *  occurs to determine the specific ITRON error code to return.
56 */
57
58#define _ITRON_Semaphore_Clarify_allocation_id_error( _id ) \
59  _ITRON_Objects_Clarify_allocation_id_error( \
60      &_ITRON_Semaphore_Information, (_id) )
61
62/*
63 *  _ITRON_Semaphore_Clarify_get_id_error
64 *
65 *  This function is invoked when an object get ID error
66 *  occurs to determine the specific ITRON error code to return.
67 */
68
69#define _ITRON_Semaphore_Clarify_get_id_error( _id ) \
70 _ITRON_Objects_Clarify_get_id_error( &_ITRON_Semaphore_Information, (_id) )
71
72/*
73 *  _ITRON_Semaphore_Free
74 *
75 *  DESCRIPTION:
76 *
77 *  This routine frees a semaphore control block to the
78 *  inactive chain of free semaphore control blocks.
79 *
80 *  Input parameters:
81 *    the_semaphore - pointer to semaphore control block
82 *
83 *  Output parameters: NONE
84 */
85
86RTEMS_INLINE_ROUTINE void _ITRON_Semaphore_Free (
87  ITRON_Semaphore_Control *the_semaphore
88)
89{
90  _ITRON_Objects_Free( &_ITRON_Semaphore_Information, &the_semaphore->Object );
91}
92
93/*PAGE
94 *
95 *  _ITRON_Semaphore_Get
96 *
97 *  DESCRIPTION:
98 *
99 *  This function maps semaphore IDs to semaphore control blocks.
100 *  If ID corresponds to a local semaphore, then it returns
101 *  the_semaphore control pointer which maps to ID and location
102 *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
103 *  resides on a remote node, then location is set to OBJECTS_REMOTE,
104 *  and the_semaphore is undefined.  Otherwise, location is set
105 *  to OBJECTS_ERROR and the_semaphore is undefined.
106 *
107 *  Input parameters:
108 *    id            - ITRON semaphore ID.
109 *    the_location  - pointer to a location variable
110 *
111 *  Output parameters:
112 *    *the_location  - location of the object
113 */
114
115RTEMS_INLINE_ROUTINE ITRON_Semaphore_Control *_ITRON_Semaphore_Get (
116  ID                 id,
117  Objects_Locations *location
118)
119{
120  return (ITRON_Semaphore_Control *)
121    _ITRON_Objects_Get( &_ITRON_Semaphore_Information, id, location );
122}
123
124/*PAGE
125 *
126 *  _ITRON_Semaphore_Is_null
127 *
128 *  This function returns TRUE if the_semaphore is NULL and FALSE otherwise.
129 *
130 *  Input parameters:
131 *    the_semaphore - pointer to semaphore control block
132 *
133 *  Output parameters:
134 *    TRUE  - if the_semaphore is NULL
135 *    FALSE - otherwise
136 */
137
138RTEMS_INLINE_ROUTINE boolean _ITRON_Semaphore_Is_null (
139  ITRON_Semaphore_Control *the_semaphore
140)
141{
142  return ( the_semaphore == NULL );
143}
144
145/*
146 *  _ITRON_Semaphore_Translate_core_semaphore_return_code
147 *
148 *  This function returns a ITRON status code based on the semaphore
149 *  status code specified.
150 *
151 *  Input parameters:
152 *    the_semaphore_status - semaphore status code to translate
153 *
154 *  Output parameters:
155 *    ITRON status code - translated ITRON status code
156 *
157 */
158
159RTEMS_INLINE_ROUTINE ER  _ITRON_Semaphore_Translate_core_semaphore_return_code (
160  uint32_t   the_semaphore_status
161)
162{
163/* XXX need to be able to return "E_RLWAI" */
164  switch ( the_semaphore_status ) {
165    case  CORE_SEMAPHORE_STATUS_SUCCESSFUL:
166      return E_OK;
167    case CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT:
168      return E_TMOUT;
169    case CORE_SEMAPHORE_WAS_DELETED:
170      return E_DLT;
171    case CORE_SEMAPHORE_TIMEOUT:
172      return E_TMOUT;
173    case CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED:
174      return E_QOVR;
175    case THREAD_STATUS_PROXY_BLOCKING:
176      return THREAD_STATUS_PROXY_BLOCKING;
177  }
178  return E_OK;   /* unreached - only to remove warnings */
179}
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif
186/* end of include file */
187
Note: See TracBrowser for help on using the repository browser.