source: rtems/c/src/lib/librtems++/rtemsSemaphore.cc @ d637822

4.104.114.84.95
Last change on this file since d637822 was 0074691a, checked in by Joel Sherrill <joel.sherrill@…>, on 07/31/97 at 22:13:29

Merged very large and much appreciated patch from Chris Johns
<cjohns@…>. This patch includes the ods68302 bsp,
the RTEMS++ class library, and the rtems++ test.

  • 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 <rtems++/rtemsSemaphore.h>
22
23/* ----
24    rtemsSemaphore
25*/
26
27rtemsSemaphore::rtemsSemaphore(const char* sname,
28                               const Scope scope,
29                               const rtems_unsigned32 counter,
30                               const WaitMode wait_mode,
31                               const Type type,
32                               const Priority priority,
33                               const Ceiling ceiling,
34                               const rtems_task_priority priority_ceiling)
35  : name(0),
36    owner(true),
37    id(0)
38{
39  strcpy(name_str, "NOID");
40  create(sname,
41         scope,
42         counter,
43         wait_mode,
44         type,
45         priority,
46         ceiling,
47         priority_ceiling); 
48}
49
50rtemsSemaphore::rtemsSemaphore(const char *sname, const rtems_unsigned32 node)
51  : name(0),
52    owner(false),
53    id(0)
54{
55  strcpy(name_str, "NOID");
56  connect(sname, node);
57}
58
59rtemsSemaphore::rtemsSemaphore(const rtemsSemaphore& semaphore)
60  : name(0),
61    owner(false),
62    id(0)
63{
64  name = semaphore.name;
65  strcpy(name_str, semaphore.name_str);
66  id = semaphore.id;
67}
68
69rtemsSemaphore::rtemsSemaphore()
70  : name(0),
71    owner(false),
72    id(0)
73{
74  strcpy(name_str, "NOID");
75}
76
77rtemsSemaphore::~rtemsSemaphore()
78{
79  destroy();
80}
81
82void rtemsSemaphore::make_invalid()
83{
84  strcpy(name_str, "NOID");
85  name = 0;
86  id = 0;
87  owner = false;
88}
89
90const rtems_status_code rtemsSemaphore::create(const char* sname,
91                                               const Scope scope,
92                                               const rtems_unsigned32 counter,
93                                               const WaitMode wait_mode,
94                                               const Type type,
95                                               const Priority priority,
96                                               const Ceiling ceiling,
97                                               const rtems_task_priority priority_ceiling)
98{
99  if (id)
100    return set_status_code(RTEMS_ILLEGAL_ON_SELF);
101
102  owner = true;
103 
104  strcpy(name_str, "    ");
105  for (int c = 0; (c < 4) && (sname[c] != '\0'); c++)
106    name_str[c] = sname[c];
107  name = rtems_build_name(name_str[0],
108                          name_str[1],
109                          name_str[2],
110                          name_str[3]);
111 
112  set_status_code(rtems_semaphore_create(name,
113                                         counter,
114                                         scope | wait_mode | type | priority | ceiling,
115                                         priority_ceiling,
116                                         &id));
117
118  if (unsuccessful())
119  {
120    make_invalid();
121  }
122 
123  return last_status_code();
124}
125
126const rtems_status_code rtemsSemaphore::destroy()
127{
128  if (id && owner)
129  {
130    set_status_code(rtems_semaphore_delete(id));
131    make_invalid();
132  }
133  else
134    set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE);
135 
136  return last_status_code();
137}
138
139const rtemsSemaphore& rtemsSemaphore::operator=(const rtemsSemaphore& semaphore)
140{
141  if (!owner)
142  {
143    name = semaphore.name;
144    id = semaphore.id;
145  }
146  return *this;
147}
148
149const rtems_status_code rtemsSemaphore::connect(const char *sname,
150                                                const rtems_unsigned32 node)
151{
152  if (id && owner)
153    return set_status_code(RTEMS_UNSATISFIED);
154
155  // change state to not owner
156  owner = false;
157 
158  strcpy(name_str, "    ");
159  for (int c = 0; (c < 4) && (sname[c] != '\0'); c++)
160    name_str[c] = sname[c];
161  name = rtems_build_name(name_str[0],
162                          name_str[1],
163                          name_str[2],
164                          name_str[3]);
165 
166  set_status_code(rtems_semaphore_ident(name, node, &id));
167
168  if (unsuccessful())
169  {
170    make_invalid();
171  }
172 
173  return last_status_code();
174}
Note: See TracBrowser for help on using the repository browser.