source: rtems/cpukit/posix/src/semaphorecreatesupp.c @ 799c767

4.104.114.84.95
Last change on this file since 799c767 was 799c767, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/99 at 18:00:15

Split the POSIX semaphore manager into multiple files.

  • Property mode set to 100644
File size: 2.5 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
24int _POSIX_Semaphore_Create_support(
25  const char                *name,
26  int                        pshared,
27  unsigned int               value,
28  POSIX_Semaphore_Control  **the_sem
29)
30{
31  POSIX_Semaphore_Control   *the_semaphore;
32  CORE_semaphore_Attributes *the_sem_attr;
33
34  _Thread_Disable_dispatch();
35 
36  /* Sharing semaphores among processes is not currently supported */
37  if (pshared != 0) {
38    _Thread_Enable_dispatch();
39    set_errno_and_return_minus_one( ENOSYS );
40  }
41
42  the_semaphore = _POSIX_Semaphore_Allocate();
43 
44  if ( !the_semaphore ) {
45    _Thread_Enable_dispatch();
46    set_errno_and_return_minus_one( ENOSPC );
47  }
48 
49#if defined(RTEMS_MULTIPROCESSING)
50  if ( pshared == PTHREAD_PROCESS_SHARED &&
51       !( _Objects_MP_Allocate_and_open( &_POSIX_Semaphore_Information, 0,
52                            the_semaphore->Object.id, FALSE ) ) ) {
53    _POSIX_Semaphore_Free( the_semaphore );
54    _Thread_Enable_dispatch();
55    set_errno_and_return_minus_one( EAGAIN );
56  }
57#endif
58 
59  the_semaphore->process_shared  = pshared;
60
61  if ( name ) {
62    the_semaphore->named = TRUE;
63    the_semaphore->open_count = 1;
64    the_semaphore->linked = TRUE;
65  }
66  else
67    the_semaphore->named = FALSE;
68
69  the_sem_attr = &the_semaphore->Semaphore.Attributes;
70 
71  /* XXX
72   *
73   *  Note should this be based on the current scheduling policy?
74   */
75
76  the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
77
78  /*
79   *  This effectively disables limit checking.
80   */
81
82  the_sem_attr->maximum_count = 0xFFFFFFFF;
83
84  _CORE_semaphore_Initialize(
85    &the_semaphore->Semaphore,
86    OBJECTS_POSIX_SEMAPHORES,
87    the_sem_attr,
88    value,
89    0      /* XXX - proxy_extract_callout is unused */
90  );
91 
92  /* XXX - need Names to be a string!!! */
93  _Objects_Open(
94    &_POSIX_Semaphore_Information,
95    &the_semaphore->Object,
96    (char *) name
97  );
98 
99  *the_sem = the_semaphore;
100 
101#if defined(RTEMS_MULTIPROCESSING)
102  if ( pshared == PTHREAD_PROCESS_SHARED )
103    _POSIX_Semaphore_MP_Send_process_packet(
104      POSIX_SEMAPHORE_MP_ANNOUNCE_CREATE,
105      the_semaphore->Object.id,
106      (char *) name,
107      0                /* proxy id - Not used */
108    );
109#endif
110 
111  _Thread_Enable_dispatch();
112  return 0;
113}
Note: See TracBrowser for help on using the repository browser.