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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [semaphorecreatesupp.c] - Blame information for rev 532

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

Line No. Rev Author Line
1 30 unneback
/*
2
 *  $Id: semaphorecreatesupp.c,v 1.2 2001-09-27 11:59:17 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
#ifndef PATH_MAX
20
#define PATH_MAX 1024
21
#endif
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
 
32
int _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
 
129
    );
130
#endif
131
 
132
  _Thread_Enable_dispatch();
133
  return 0;
134
}

powered by: WebSVN 2.1.0

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