source: rtems/cpukit/posix/src/semaphorecreatesupp.c @ aaf6063

4.104.114.84.95
Last change on this file since aaf6063 was f42b726, checked in by Joel Sherrill <joel.sherrill@…>, on 01/24/01 at 14:17:28

2001-01-24 Ralf Corsepius <corsepiu@…>

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