source: rtems/cpukit/posix/src/semaphorecreatesupp.c @ 874297f3

4.104.114.84.95
Last change on this file since 874297f3 was 874297f3, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/16/04 at 10:01:03

Remove stray white spaces.

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