source: rtems/c/src/exec/posix/src/semaphorecreatesupp.c @ 64f55e7

4.104.114.84.95
Last change on this file since 64f55e7 was 0ebf5694, checked in by Jennifer Averett <Jennifer.Averett@…>, on 11/22/99 at 16:07:02

+ Cleaned up comments.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  $Id$
3 */
4
5#include <stdarg.h>
6
7#include <errno.h>
8#include <fcntl.h>
9#include <pthread.h>
10#include <semaphore.h>
11#include <limits.h>
12
13#include <rtems/system.h>
14#include <rtems/score/object.h>
15#include <rtems/posix/semaphore.h>
16#include <rtems/posix/time.h>
17#include <rtems/posix/seterr.h>
18
19/*PAGE
20 *
21 *  _POSIX_Semaphore_Create_support
22 *
23 *  This routine does the actual creation and initialization of
24 *  a poxix semaphore.  It is a support routine for sem_init and
25 *  sem_open.
26 */
27
28int _POSIX_Semaphore_Create_support(
29  const char                *name,
30  int                        pshared,
31  unsigned int               value,
32  POSIX_Semaphore_Control  **the_sem
33)
34{
35  POSIX_Semaphore_Control   *the_semaphore;
36  CORE_semaphore_Attributes *the_sem_attr;
37
38  _Thread_Disable_dispatch();
39 
40  /* Sharing semaphores among processes is not currently supported */
41  if (pshared != 0) {
42    _Thread_Enable_dispatch();
43    set_errno_and_return_minus_one( ENOSYS );
44  }
45
46  the_semaphore = _POSIX_Semaphore_Allocate();
47 
48  if ( !the_semaphore ) {
49    _Thread_Enable_dispatch();
50    set_errno_and_return_minus_one( ENOSPC );
51  }
52 
53#if defined(RTEMS_MULTIPROCESSING)
54  if ( pshared == PTHREAD_PROCESS_SHARED &&
55       !( _Objects_MP_Allocate_and_open( &_POSIX_Semaphore_Information, 0,
56                            the_semaphore->Object.id, FALSE ) ) ) {
57    _POSIX_Semaphore_Free( the_semaphore );
58    _Thread_Enable_dispatch();
59    set_errno_and_return_minus_one( EAGAIN );
60  }
61#endif
62 
63  the_semaphore->process_shared  = pshared;
64
65  if ( name ) {
66    the_semaphore->named = TRUE;
67    the_semaphore->open_count = 1;
68    the_semaphore->linked = TRUE;
69  }
70  else
71    the_semaphore->named = FALSE;
72
73  the_sem_attr = &the_semaphore->Semaphore.Attributes;
74 
75  /*
76   *  POSIX does not appear to specify what the discipline for
77   *  blocking tasks on this semaphore should be.  It could somehow
78   *  be derived from the current scheduling policy.  One
79   *  thing is certain, no matter what we decide, it won't be
80   *  the same as  all other POSIX implementations. :)
81   */
82
83  the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
84
85  /*
86   *  This effectively disables limit checking.
87   */
88
89  the_sem_attr->maximum_count = 0xFFFFFFFF;
90
91  _CORE_semaphore_Initialize(
92    &the_semaphore->Semaphore,
93    OBJECTS_POSIX_SEMAPHORES,
94    the_sem_attr,
95    value,
96    NULL                 /* multiprocessing is not supported */
97  );
98
99  /*
100   *  Make the semaphore available for use.
101   */
102 
103  _Objects_Open(
104    &_POSIX_Semaphore_Information,
105    &the_semaphore->Object,
106    (char *) name
107  );
108 
109  *the_sem = the_semaphore;
110 
111#if defined(RTEMS_MULTIPROCESSING)
112  if ( pshared == PTHREAD_PROCESS_SHARED )
113    _POSIX_Semaphore_MP_Send_process_packet(
114      POSIX_SEMAPHORE_MP_ANNOUNCE_CREATE,
115      the_semaphore->Object.id,
116      (char *) name,
117      0                           /* proxy id - Not used */
118    );
119#endif
120 
121  _Thread_Enable_dispatch();
122  return 0;
123}
Note: See TracBrowser for help on using the repository browser.