This is Unofficial EPICS BASE Doxygen Site
osdMutex.c File Reference
#include <stdio.h>
#include <limits.h>
#include <windows.h>
#include "libComAPI.h"
#include "epicsMutex.h"
#include "epicsAssert.h"
#include "epicsStdio.h"
+ Include dependency graph for osdMutex.c:

Go to the source code of this file.

Classes

struct  epicsMutexOSD
 

Macros

#define VC_EXTRALEAN
 
#define STRICT
 
#define _WIN32_WINNT   0x0400
 

Typedefs

typedef struct epicsMutexOSD epicsMutexOSD
 

Functions

epicsMutexOSDepicsMutexOsdCreate (void)
 
void epicsMutexOsdDestroy (epicsMutexOSD *pSem)
 
void epicsMutexOsdUnlock (epicsMutexOSD *pSem)
 
epicsMutexLockStatus epicsMutexOsdLock (epicsMutexOSD *pSem)
 
epicsMutexLockStatus epicsMutexOsdTryLock (epicsMutexOSD *pSem)
 
void epicsMutexOsdShow (epicsMutexOSD *pSem, unsigned level)
 

Macro Definition Documentation

#define _WIN32_WINNT   0x0400

Definition at line 41 of file osdMutex.c.

#define STRICT

Definition at line 24 of file osdMutex.c.

#define VC_EXTRALEAN

Definition at line 23 of file osdMutex.c.

Typedef Documentation

typedef struct epicsMutexOSD epicsMutexOSD

Function Documentation

epicsMutexOSD* epicsMutexOsdCreate ( void  )

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

Definition at line 63 of file osdMutex.c.

64 {
65  epicsMutexOSD * pSem;
66 
67  if ( ! weHaveInitialized ) {
68  BOOL status;
69  OSVERSIONINFO osInfo;
70  osInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
71  status = GetVersionEx ( & osInfo );
72  thisIsNT = status && ( osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT );
73  weHaveInitialized = 1;
74  }
75 
76  pSem = malloc ( sizeof (*pSem) );
77  if ( pSem ) {
78  if ( thisIsNT ) {
79  InitializeCriticalSection ( &pSem->os.criticalSection );
80  }
81  else {
82  pSem->os.mutex = CreateMutex ( NULL, FALSE, NULL );
83  if ( pSem->os.mutex == 0 ) {
84  free ( pSem );
85  pSem = 0;
86  }
87  }
88  }
89  return pSem;
90 }
#define FALSE
Definition: dbDefs.h:32
HANDLE mutex
Definition: osdMutex.c:52
pvd::Status status
#define NULL
Definition: catime.c:38
union epicsMutexOSD::@18 os
CRITICAL_SECTION criticalSection
Definition: osdMutex.c:53
void epicsMutexOsdDestroy ( epicsMutexOSD pSem)

Definition at line 95 of file osdMutex.c.

96 {
97  if ( thisIsNT ) {
98  DeleteCriticalSection ( &pSem->os.criticalSection );
99  }
100  else {
101  CloseHandle ( pSem->os.mutex );
102  }
103  free ( pSem );
104 }
HANDLE mutex
Definition: osdMutex.c:52
union epicsMutexOSD::@18 os
CRITICAL_SECTION criticalSection
Definition: osdMutex.c:53
epicsMutexLockStatus epicsMutexOsdLock ( epicsMutexOSD pSem)

Definition at line 123 of file osdMutex.c.

124 {
125  if ( thisIsNT ) {
126  EnterCriticalSection ( &pSem->os.criticalSection );
127  }
128  else {
129  DWORD status = WaitForSingleObject ( pSem->os.mutex, INFINITE );
130  if ( status != WAIT_OBJECT_0 ) {
131  return epicsMutexLockError;
132  }
133  }
134  return epicsMutexLockOK;
135 }
HANDLE mutex
Definition: osdMutex.c:52
pvd::Status status
union epicsMutexOSD::@18 os
CRITICAL_SECTION criticalSection
Definition: osdMutex.c:53
void epicsMutexOsdShow ( epicsMutexOSD pSem,
unsigned  level 
)

Definition at line 167 of file osdMutex.c.

168 {
169  if ( thisIsNT ) {
170  printf ("epicsMutex: win32 critical section at %p\n",
171  (void * ) & pSem->os.criticalSection );
172  }
173  else {
174  printf ( "epicsMutex: win32 mutex at %p\n",
175  ( void * ) pSem->os.mutex );
176  }
177 }
HANDLE mutex
Definition: osdMutex.c:52
#define printf
Definition: epicsStdio.h:41
union epicsMutexOSD::@18 os
CRITICAL_SECTION criticalSection
Definition: osdMutex.c:53
epicsMutexLockStatus epicsMutexOsdTryLock ( epicsMutexOSD pSem)

Definition at line 140 of file osdMutex.c.

141 {
142  if ( thisIsNT ) {
143  if ( TryEnterCriticalSection ( &pSem->os.criticalSection ) ) {
144  return epicsMutexLockOK;
145  }
146  else {
147  return epicsMutexLockTimeout;
148  }
149  }
150  else {
151  DWORD status = WaitForSingleObject ( pSem->os.mutex, 0 );
152  if ( status != WAIT_OBJECT_0 ) {
153  if (status == WAIT_TIMEOUT) {
154  return epicsMutexLockTimeout;
155  }
156  else {
157  return epicsMutexLockError;
158  }
159  }
160  }
161  return epicsMutexLockOK;
162 }
HANDLE mutex
Definition: osdMutex.c:52
pvd::Status status
union epicsMutexOSD::@18 os
CRITICAL_SECTION criticalSection
Definition: osdMutex.c:53
void epicsMutexOsdUnlock ( epicsMutexOSD pSem)

Definition at line 109 of file osdMutex.c.

110 {
111  if ( thisIsNT ) {
112  LeaveCriticalSection ( &pSem->os.criticalSection );
113  }
114  else {
115  BOOL success = ReleaseMutex ( pSem->os.mutex );
116  assert ( success );
117  }
118 }
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
HANDLE mutex
Definition: osdMutex.c:52
union epicsMutexOSD::@18 os
CRITICAL_SECTION criticalSection
Definition: osdMutex.c:53