source: rtems/cpukit/posix/include/rtems/posix/semaphore.h @ 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: 3.8 KB
Line 
1/**
2 * @file rtems/posix/semaphore.h
3 */
4
5/*  rtems/posix/semaphore.h
6 *
7 *  This include file contains all the private support information for
8 *  POSIX Semaphores.
9 *
10 *  COPYRIGHT (c) 1989-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#ifndef _RTEMS_POSIX_SEMAPHORE_H
21#define _RTEMS_POSIX_SEMAPHORE_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <semaphore.h>
28#include <rtems/score/coresem.h>
29
30#define SEM_FAILED (sem_t *) -1
31
32/*
33 *  Data Structure used to manage a POSIX semaphore
34 */
35
36typedef struct {
37   Objects_Control         Object;
38   int                     process_shared;
39   boolean                 named;
40   boolean                 linked;
41   uint32_t                open_count;
42   CORE_semaphore_Control  Semaphore;
43}  POSIX_Semaphore_Control;
44
45/*
46 *  The following defines the information control block used to manage
47 *  this class of objects.
48 */
49
50POSIX_EXTERN Objects_Information  _POSIX_Semaphore_Information;
51
52/*
53 *  _POSIX_Semaphore_Manager_initialization
54 *
55 *  DESCRIPTION:
56 *
57 *  This routine performs the initialization necessary for this manager.
58 */
59
60void _POSIX_Semaphore_Manager_initialization(
61  uint32_t   maximum_semaphorees
62);
63
64/*
65 *  _POSIX_Semaphore_Allocate
66 *
67 *  DESCRIPTION:
68 *
69 *  This function allocates a semaphore control block from
70 *  the inactive chain of free semaphore control blocks.
71 */
72
73RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void );
74
75/*
76 *  _POSIX_Semaphore_Free
77 *
78 *  DESCRIPTION:
79 *
80 *  This routine frees a semaphore control block to the
81 *  inactive chain of free semaphore control blocks.
82 */
83
84RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free (
85  POSIX_Semaphore_Control *the_semaphore
86);
87
88/*
89 *  _POSIX_Semaphore_Get
90 *
91 *  DESCRIPTION:
92 *
93 *  This function maps semaphore IDs to semaphore control blocks.
94 *  If ID corresponds to a local semaphore, then it returns
95 *  the_semaphore control pointer which maps to ID and location
96 *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
97 *  resides on a remote node, then location is set to OBJECTS_REMOTE,
98 *  and the_semaphore is undefined.  Otherwise, location is set
99 *  to OBJECTS_ERROR and the_semaphore is undefined.
100 */
101
102RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
103  sem_t        *id,
104  Objects_Locations *location
105);
106
107/*
108 *  _POSIX_Semaphore_Is_null
109 *
110 *  DESCRIPTION:
111 *
112 *  This function returns TRUE if the_semaphore is NULL and FALSE otherwise.
113 */
114
115RTEMS_INLINE_ROUTINE boolean _POSIX_Semaphore_Is_null (
116  POSIX_Semaphore_Control *the_semaphore
117);
118
119/*
120 *  _POSIX_Semaphore_Create_support
121 *
122 *  DESCRIPTION:
123 *
124 *  This routine supports the sem_init and sem_open routines.
125 */
126
127int _POSIX_Semaphore_Create_support(
128  const char                *name,
129  int                        pshared,
130  unsigned int               value,
131  POSIX_Semaphore_Control  **the_sem
132);
133
134/*
135 *  _POSIX_Semaphore_Delete
136 *
137 *  DESCRIPTION:
138 *
139 *  This routine supports the sem_close and sem_unlink routines.
140 */
141
142void _POSIX_Semaphore_Delete(
143  POSIX_Semaphore_Control *the_semaphore
144);
145
146/*
147 *  _POSIX_Semaphore_Wait_support
148 *
149 *  DESCRIPTION:
150 *
151 *  This routine supports the sem_wait, sem_trywait, and sem_timedwait
152 *  services.
153 */
154
155int _POSIX_Semaphore_Wait_support(
156  sem_t               *sem,
157  boolean              blocking,
158  Watchdog_Interval    timeout
159);
160
161/*
162 *  _POSIX_Semaphore_Name_to_id
163 *
164 *  DESCRIPTION:
165 *
166 *  This routine performs name to id translation.
167 */
168
169int _POSIX_Semaphore_Name_to_id(
170  const char          *name,
171  sem_t          *id
172);
173
174#include <rtems/posix/semaphore.inl>
175#if defined(RTEMS_MULTIPROCESSING)
176#include <rtems/posix/semaphoremp.h>
177#endif
178
179#ifdef __cplusplus
180}
181#endif
182
183#endif
184/*  end of include file */
Note: See TracBrowser for help on using the repository browser.