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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [librtems++/] [src/] [rtemsSemaphore.cc] - Blame information for rev 535

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

Line No. Rev Author Line
1 30 unneback
/*
2
  ------------------------------------------------------------------------
3
  $Id: rtemsSemaphore.cc,v 1.2 2001-09-27 12:02:05 chris Exp $
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
 
28
rtemsSemaphore::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
 
51
rtemsSemaphore::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
 
60
rtemsSemaphore::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
 
70
rtemsSemaphore::rtemsSemaphore()
71
  : name(0),
72
    owner(false),
73
    id(0)
74
{
75
  strcpy(name_str, "NOID");
76
}
77
 
78
rtemsSemaphore::~rtemsSemaphore()
79
{
80
  destroy();
81
}
82
 
83
void rtemsSemaphore::make_invalid()
84
{
85
  strcpy(name_str, "NOID");
86
  name = 0;
87
  id = 0;
88
  owner = false;
89
}
90
 
91
const 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
 
127
const 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
 
140
const 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
 
150
const 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
}

powered by: WebSVN 2.1.0

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