OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [semaphorecreatesupp.c] - Blame information for rev 158

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
2
 *  $Id: semaphorecreatesupp.c,v 1.1.1.1 2001-07-10 09:43:03 chris Exp $
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
 
28
int _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
  if ( name ) {
47
    if( strlen(name) > PATH_MAX ) {
48
      _Thread_Enable_dispatch();
49
      set_errno_and_return_minus_one( ENAMETOOLONG );
50
    }
51
  }
52
 
53
  the_semaphore = _POSIX_Semaphore_Allocate();
54
 
55
  if ( !the_semaphore ) {
56
    _Thread_Enable_dispatch();
57
    set_errno_and_return_minus_one( ENOSPC );
58
  }
59
 
60
#if defined(RTEMS_MULTIPROCESSING)
61
  if ( pshared == PTHREAD_PROCESS_SHARED &&
62
       !( _Objects_MP_Allocate_and_open( &_POSIX_Semaphore_Information, 0,
63
                            the_semaphore->Object.id, FALSE ) ) ) {
64
    _POSIX_Semaphore_Free( the_semaphore );
65
    _Thread_Enable_dispatch();
66
    set_errno_and_return_minus_one( EAGAIN );
67
  }
68
#endif
69
 
70
  the_semaphore->process_shared  = pshared;
71
 
72
  if ( name ) {
73
    the_semaphore->named = TRUE;
74
    the_semaphore->open_count = 1;
75
    the_semaphore->linked = TRUE;
76
  }
77
  else
78
    the_semaphore->named = FALSE;
79
 
80
  the_sem_attr = &the_semaphore->Semaphore.Attributes;
81
 
82
  /*
83
   *  POSIX does not appear to specify what the discipline for
84
   *  blocking tasks on this semaphore should be.  It could somehow
85
   *  be derived from the current scheduling policy.  One
86
   *  thing is certain, no matter what we decide, it won't be
87
   *  the same as  all other POSIX implementations. :)
88
   */
89
 
90
  the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
91
 
92
  /*
93
   *  This effectively disables limit checking.
94
   */
95
 
96
  the_sem_attr->maximum_count = 0xFFFFFFFF;
97
 
98
  _CORE_semaphore_Initialize(
99
    &the_semaphore->Semaphore,
100
    OBJECTS_POSIX_SEMAPHORES,
101
    the_sem_attr,
102
    value,
103
    NULL                 /* multiprocessing is not supported */
104
  );
105
 
106
  /*
107
   *  Make the semaphore available for use.
108
   */
109
 
110
  _Objects_Open(
111
    &_POSIX_Semaphore_Information,
112
    &the_semaphore->Object,
113
    (char *) name
114
  );
115
 
116
  *the_sem = the_semaphore;
117
 
118
#if defined(RTEMS_MULTIPROCESSING)
119
  if ( pshared == PTHREAD_PROCESS_SHARED )
120
    _POSIX_Semaphore_MP_Send_process_packet(
121
      POSIX_SEMAPHORE_MP_ANNOUNCE_CREATE,
122
      the_semaphore->Object.id,
123
      (char *) name,
124
 
125
    );
126
#endif
127
 
128
  _Thread_Enable_dispatch();
129
  return 0;
130
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.