This is Unofficial EPICS BASE Doxygen Site
osdMutex.c File Reference
#include <assert.h>
#include <stdio.h>
#include <rtems.h>
#include <rtems/error.h>
#include "epicsStdio.h"
#include "epicsMutex.h"
#include "epicsEvent.h"
#include "errlog.h"
+ Include dependency graph for osdMutex.c:

Go to the source code of this file.

Macros

#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__   1
 
#define RTEMS_FAST_MUTEX
 
#define SEMSTAT(i)
 

Functions

struct epicsMutexOSDepicsMutexOsdCreate (void)
 
void epicsMutexOsdDestroy (struct epicsMutexOSD *id)
 
void epicsMutexOsdUnlock (struct epicsMutexOSD *id)
 
epicsMutexLockStatus epicsMutexOsdLock (struct epicsMutexOSD *id)
 
epicsMutexLockStatus epicsMutexOsdTryLock (struct epicsMutexOSD *id)
 
LIBCOM_API void epicsMutexOsdShow (struct epicsMutexOSD *id, unsigned int level)
 

Macro Definition Documentation

#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__   1

Definition at line 18 of file osdMutex.c.

#define RTEMS_FAST_MUTEX

Definition at line 30 of file osdMutex.c.

#define SEMSTAT (   i)

Definition at line 39 of file osdMutex.c.

Function Documentation

struct epicsMutexOSD* epicsMutexOsdCreate ( void  )

The following are interfaces to the OS dependent implementation and should NOT be called directly by user code.

Definition at line 43 of file osdMutex.c.

44 {
45  rtems_status_code sc;
46  rtems_id sid;
47  rtems_interrupt_level level;
48  static char c1 = 'a';
49  static char c2 = 'a';
50  static char c3 = 'a';
51 
52  sc = rtems_semaphore_create (rtems_build_name ('M', c3, c2, c1),
53  1,
54  RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY|RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
55  0,
56  &sid);
57  if (sc != RTEMS_SUCCESSFUL) {
58  errlogPrintf ("Can't create mutex semaphore: %s\n", rtems_status_text (sc));
59  return NULL;
60  }
61  rtems_interrupt_disable (level);
62  if (c1 == 'z') {
63  if (c2 == 'z') {
64  if (c3 == 'z') {
65  c3 = 'a';
66  }
67  else {
68  c3++;
69  }
70  c2 = 'a';
71  }
72  else {
73  c2++;
74  }
75  c1 = 'a';
76  }
77  else {
78  c1++;
79  }
80  rtems_interrupt_enable (level);
81 #ifdef RTEMS_FAST_MUTEX
82  {
83  Semaphore_Control *the_semaphore;
84  Objects_Locations location;
85 
86  the_semaphore = _Semaphore_Get( sid, &location );
87  _Thread_Enable_dispatch();
88 
89  return (struct epicsMutexOSD *)the_semaphore;
90  }
91 #endif
92  return (struct epicsMutexOSD *)sid;
93 }
#define NULL
Definition: catime.c:38
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void epicsMutexOsdDestroy ( struct epicsMutexOSD id)

Definition at line 95 of file osdMutex.c.

96 {
97  rtems_status_code sc;
98  rtems_id sid;
99 #ifdef RTEMS_FAST_MUTEX
100  Semaphore_Control *the_semaphore = (Semaphore_Control *)id;
101  sid = the_semaphore->Object.id;
102 #else
103  sid = (rtems_id)id;
104 #endif
105  sc = rtems_semaphore_delete (sid);
106  if (sc == RTEMS_RESOURCE_IN_USE) {
107  rtems_semaphore_release (sid);
108  sc = rtems_semaphore_delete (sid);
109  }
110  if (sc != RTEMS_SUCCESSFUL)
111  errlogPrintf ("Can't destroy semaphore %p (%lx): %s\n", id, (unsigned long)sid, rtems_status_text (sc));
112 }
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
epicsMutexLockStatus epicsMutexOsdLock ( struct epicsMutexOSD id)

Definition at line 131 of file osdMutex.c.

132 {
133 #ifdef RTEMS_FAST_MUTEX
134  Semaphore_Control *the_semaphore = (Semaphore_Control *)id;
135  ISR_Level level;
136  SEMSTAT(0)
137  _ISR_Disable( level );
138  _CORE_mutex_Seize(
139  &the_semaphore->Core_control.mutex,
140  the_semaphore->Object.id,
141  1, /* TRUE or FALSE */
142  0, /* same as passed to obtain -- ticks */
143  level
144  );
145  if (_Thread_Executing->Wait.return_code == 0)
146  return epicsMutexLockOK;
147  else
148  return epicsMutexLockError;
149 #else
150  SEMSTAT(0)
151  return((epicsEventWait (id) == epicsEventWaitOK)
152  ?epicsMutexLockOK : epicsMutexLockError);
153 #endif
154 }
#define epicsEventWait(ID)
Definition: osdEvent.h:19
#define SEMSTAT(i)
Definition: osdMutex.c:39
#define epicsEventWaitOK
Old name provided for backwards compatibility.
Definition: epicsEvent.h:58
if(yy_init)
Definition: scan.c:972
LIBCOM_API void epicsMutexOsdShow ( struct epicsMutexOSD id,
unsigned int  level 
)

Definition at line 188 of file osdMutex.c.

189 {
190 #ifdef RTEMS_FAST_MUTEX
191  Semaphore_Control *the_semaphore = (Semaphore_Control *)id;
192  id = (struct epicsMutexOSD *)the_semaphore->Object.id;
193 #endif
194  epicsEventShow ((epicsEventId)id,level);
195 }
LIBCOM_API void epicsEventShow(epicsEventId id, unsigned int level)
Display information about the semaphore.
Definition: osdEvent.c:150
epicsMutexLockStatus epicsMutexOsdTryLock ( struct epicsMutexOSD id)

Definition at line 156 of file osdMutex.c.

157 {
158 #ifdef RTEMS_FAST_MUTEX
159  Semaphore_Control *the_semaphore = (Semaphore_Control *)id;
160  ISR_Level level;
161  SEMSTAT(2)
162  _ISR_Disable( level );
163  _CORE_mutex_Seize(
164  &the_semaphore->Core_control.mutex,
165  the_semaphore->Object.id,
166  0, /* TRUE or FALSE */
167  0, /* same as passed to obtain -- ticks */
168  level
169  );
170  if (_Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_SUCCESSFUL)
171  return epicsMutexLockOK;
172  else if (_Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT)
173  return epicsMutexLockTimeout;
174  else
175  return epicsMutexLockError;
176 #else
178  SEMSTAT(2)
179  status = epicsEventTryWait(id);
180  return((status==epicsEventWaitOK
181  ? epicsMutexLockOK
182  : (status==epicsEventWaitTimeout)
183  ? epicsMutexLockTimeout
184  : epicsMutexLockError));
185 #endif
186 }
HANDLE mutex
Definition: osdMutex.c:52
pvd::Status status
#define SEMSTAT(i)
Definition: osdMutex.c:39
LIBCOM_API epicsEventStatus epicsEventTryWait(epicsEventId id)
Similar to wait() except that if the event is currenly empty the call will return immediately with st...
Definition: osdEvent.c:145
#define epicsEventWaitOK
Old name provided for backwards compatibility.
Definition: epicsEvent.h:58
if(yy_init)
Definition: scan.c:972
#define epicsEventWaitStatus
Old name provided for backwards compatibility.
Definition: epicsEvent.h:56
void epicsMutexOsdUnlock ( struct epicsMutexOSD id)

Definition at line 114 of file osdMutex.c.

115 {
116 #ifdef RTEMS_FAST_MUTEX
117  Semaphore_Control *the_semaphore = (Semaphore_Control *)id;
118  _Thread_Disable_dispatch();
119  _CORE_mutex_Surrender (
120  &the_semaphore->Core_control.mutex,
121  the_semaphore->Object.id,
122  NULL
123  );
124  _Thread_Enable_dispatch();
125 #else
126  epicsEventSignal (id);
127 #endif
128 
129 }
#define NULL
Definition: catime.c:38
#define epicsEventSignal(ID)
A synonym for epicsEventTrigger().
Definition: epicsEvent.h:172