source: rtems/cpukit/posix/src/semaphorecreatesupp.c @ 3c465878

4.104.114.84.95
Last change on this file since 3c465878 was 3c465878, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/02 at 22:33:47

2002-07-01 Joel Sherrill <joel@…>

  • Mega patch merge to change the format of the object IDs to loosen the dependency between the SCORE and the various APIs. There was considerable work to simplify the object name management and it appears that the name_table field is no longer needed. This patch also includes the addition of the internal mutex which is currently only used to protect some types of allocation and deallocation. This significantly can reduce context switch latency under certain circumstances. In particular, some heap/region operations were O(n) and had dispatching disabled. This should help enormously. With this merge, the patch is not as clean as it should be. In particular, the documentation has not been modified to reflect the new object ID layout, the IDs in the test screens are not updated, and _Objects_Get_information needs to be a real routine not inlined. As part of this patch a lot of MP code for thread/proxy blocking was made conditional and cleaned up.
  • include/rtems/posix/key.h, src/cond.c, src/condinit.c, src/intr.c, src/key.c, src/keycreate.c, src/keydelete.c, src/killinfo.c, src/mqueue.c, src/mqueuecreatesupp.c, src/mutex.c, src/mutexinit.c, src/psignal.c, src/pthread.c, src/semaphore.c, src/semaphorecreatesupp.c: Modified as part of above.
  • 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.