source: rtems/c/src/librtems++/src/rtemsSemaphore.cc @ 8548fe0

4.104.114.84.95
Last change on this file since 8548fe0 was 2936b425, checked in by Joel Sherrill <joel.sherrill@…>, on 01/23/98 at 17:45:05

Solaris port updates from Chris Johns

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2  ------------------------------------------------------------------------
3  $Id$
4  ------------------------------------------------------------------------
5
6  COPYRIGHT (c) 1997
7  Objective Design Systems Ltd Pty (ODS)
8  All rights reserved (R) Objective Design Systems Ltd Pty
9 
10  The license and distribution terms for this file may be found in the
11  file LICENSE in this distribution or at
12  http://www.OARcorp.com/rtems/license.html.
13
14  ------------------------------------------------------------------------
15
16  See header file.
17
18  ------------------------------------------------------------------------
19*/
20
21#include <string.h>
22#include <rtems++/rtemsSemaphore.h>
23
24/* ----
25    rtemsSemaphore
26*/
27
28rtemsSemaphore::rtemsSemaphore(const char* sname,
29                               const Scope scope,
30                               const rtems_unsigned32 counter,
31                               const WaitMode wait_mode,
32                               const Type type,
33                               const Priority priority,
34                               const Ceiling ceiling,
35                               const rtems_task_priority priority_ceiling)
36  : name(0),
37    owner(true),
38    id(0)
39{
40  strcpy(name_str, "NOID");
41  create(sname,
42         scope,
43         counter,
44         wait_mode,
45         type,
46         priority,
47         ceiling,
48         priority_ceiling); 
49}
50
51rtemsSemaphore::rtemsSemaphore(const char *sname, const rtems_unsigned32 node)
52  : name(0),
53    owner(false),
54    id(0)
55{
56  strcpy(name_str, "NOID");
57  connect(sname, node);
58}
59
60rtemsSemaphore::rtemsSemaphore(const rtemsSemaphore& semaphore)
61  : name(0),
62    owner(false),
63    id(0)
64{
65  name = semaphore.name;
66  strcpy(name_str, semaphore.name_str);
67  id = semaphore.id;
68}
69
70rtemsSemaphore::rtemsSemaphore()
71  : name(0),
72    owner(false),
73    id(0)
74{
75  strcpy(name_str, "NOID");
76}
77
78rtemsSemaphore::~rtemsSemaphore()
79{
80  destroy();
81}
82
83void rtemsSemaphore::make_invalid()
84{
85  strcpy(name_str, "NOID");
86  name = 0;
87  id = 0;
88  owner = false;
89}
90
91const rtems_status_code rtemsSemaphore::create(const char* sname,
92                                               const Scope scope,
93                                               const rtems_unsigned32 counter,
94                                               const WaitMode wait_mode,
95                                               const Type type,
96                                               const Priority priority,
97                                               const Ceiling ceiling,
98                                               const rtems_task_priority priority_ceiling)
99{
100  if (id)
101    return set_status_code(RTEMS_ILLEGAL_ON_SELF);
102
103  owner = true;
104 
105  strcpy(name_str, "    ");
106  for (int c = 0; (c < 4) && (sname[c] != '\0'); c++)
107    name_str[c] = sname[c];
108  name = rtems_build_name(name_str[0],
109                          name_str[1],
110                          name_str[2],
111                          name_str[3]);
112 
113  set_status_code(rtems_semaphore_create(name,
114                                         counter,
115                                         scope | wait_mode | type | priority | ceiling,
116                                         priority_ceiling,
117                                         &id));
118
119  if (unsuccessful())
120  {
121    make_invalid();
122  }
123 
124  return last_status_code();
125}
126
127const rtems_status_code rtemsSemaphore::destroy()
128{
129  if (id && owner)
130  {
131    set_status_code(rtems_semaphore_delete(id));
132    make_invalid();
133  }
134  else
135    set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE);
136 
137  return last_status_code();
138}
139
140const rtemsSemaphore& rtemsSemaphore::operator=(const rtemsSemaphore& semaphore)
141{
142  if (!owner)
143  {
144    name = semaphore.name;
145    id = semaphore.id;
146  }
147  return *this;
148}
149
150const rtems_status_code rtemsSemaphore::connect(const char *sname,
151                                                const rtems_unsigned32 node)
152{
153  if (id && owner)
154    return set_status_code(RTEMS_UNSATISFIED);
155
156  // change state to not owner
157  owner = false;
158 
159  strcpy(name_str, "    ");
160  for (int c = 0; (c < 4) && (sname[c] != '\0'); c++)
161    name_str[c] = sname[c];
162  name = rtems_build_name(name_str[0],
163                          name_str[1],
164                          name_str[2],
165                          name_str[3]);
166 
167  set_status_code(rtems_semaphore_ident(name, node, &id));
168
169  if (unsuccessful())
170  {
171    make_invalid();
172  }
173 
174  return last_status_code();
175}
Note: See TracBrowser for help on using the repository browser.