RWLockImplLxrt35.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
25 
27 #include <icl_core/os_lxrt.h>
28 
29 #include "icl_core_thread/Common.h"
30 
31 #undef STRICT_LXRT_CHECKS
32 
33 
34 namespace icl_core {
35 namespace thread {
36 
38  : m_rwlock(NULL)
39 {
40 #ifdef STRICT_LXRT_CHECKS
42  {
43  PRINTF("RWLockImplLxrt35::RWLockImplLxrt35: Called from a Linux task!\n");
44  return;
45  }
46 #endif
47  m_rwlock = new pthread_rwlock_t;
48  pthread_rwlock_init_rt(m_rwlock, NULL);
49 }
50 
52 {
53 #ifdef STRICT_LXRT_CHECKS
55  {
56  PRINTF("RWLockImplLxrt35::~RWLockImplLxrt35: Called from a Linux task!\n");
57  return;
58  }
59 #endif
60  if (m_rwlock)
61  {
62  pthread_rwlock_destroy_rt(m_rwlock);
63  delete m_rwlock;
64  m_rwlock = NULL;
65  }
66 }
67 
69 {
70 #ifdef STRICT_LXRT_CHECKS
72  {
73  PRINTF("RWLockImplLxrt35::readLock: Called from a Linux task!\n");
74  return false;
75  }
76 #endif
77  return pthread_rwlock_rdlock_rt(m_rwlock) == 0;
78 }
79 
81 {
82 #ifdef STRICT_LXRT_CHECKS
84  {
85  PRINTF("RWLockImplLxrt35::readLock: Called from a Linux task!\n");
86  return false;
87  }
88 #endif
89  struct timespec timeout_absolute_timespec = timeout.systemTimespec();
90  int ret = pthread_rwlock_timedrdlock_rt(m_rwlock, &timeout_absolute_timespec);
91  return (ret == 0);
92 }
93 
95 {
96 #ifdef STRICT_LXRT_CHECKS
98  {
99  PRINTF("RWLockImplLxrt35::readLock: Called from a Linux task!\n");
100  return false;
101  }
102 #endif
103  return readLock(impl::getAbsoluteTimeout(timeout));
104 }
105 
107 {
108 #ifdef STRICT_LXRT_CHECKS
110  {
111  PRINTF("RWLockImplLxrt35::tryReadLock: Called from a Linux task!\n");
112  return false;
113  }
114 #endif
115  int ret = pthread_rwlock_tryrdlock_rt(m_rwlock);
116  return (ret == 0);
117 }
118 
120 {
121 #ifdef STRICT_LXRT_CHECKS
123  {
124  PRINTF("RWLockImplLxrt35::writeLock: Called from a Linux task!\n");
125  return false;
126  }
127 #endif
128  return pthread_rwlock_wrlock_rt(m_rwlock) == 0;
129 }
130 
132 {
133 #ifdef STRICT_LXRT_CHECKS
135  {
136  PRINTF("RWLockImplLxrt35::writeLock: Called from a Linux task!\n");
137  return false;
138  }
139 #endif
140  struct timespec timeout_absolute_timespec = timeout.systemTimespec();
141  int ret = pthread_rwlock_timedwrlock_rt(m_rwlock, &timeout_absolute_timespec);
142  return (ret == 0);
143 }
144 
146 {
147 #ifdef STRICT_LXRT_CHECKS
149  {
150  PRINTF("RWLockImplLxrt35::writeLock: Called from a Linux task!\n");
151  return false;
152  }
153 #endif
154  return writeLock(impl::getAbsoluteTimeout(timeout));
155 }
156 
158 {
159 #ifdef STRICT_LXRT_CHECKS
161  {
162  PRINTF("RWLockImplLxrt35::tryWriteLock: Called from a Linux task!\n");
163  return false;
164  }
165 #endif
166  // ATTENTION: Calling pthread_rwlock_trywrlock_rt() while another
167  // thread holds a read lock seems to be buggy in RTAI 3.3, so the
168  // following does NOT work:
169  // int ret = pthread_rwlock_trywrlock_rt(rwlock);
170  // return (ret == 0);
171  // Therefore we call WriteLock() with a very short timeout!
172  static icl_core::TimeSpan try_write_lock_timeout(0, 1);
173  return writeLock(try_write_lock_timeout);
174 }
175 
177 {
178 #ifdef STRICT_LXRT_CHECKS
180  {
181  PRINTF("RWLockImplLxrt35::unlock: Called from a Linux task!\n");
182  return;
183  }
184 #endif
185  pthread_rwlock_unlock_rt(rwlock);
186 }
187 
188 }
189 }
TimeStamp getAbsoluteTimeout(const TimeSpan &timeout_relative)
Definition: Common.h:59
Represents absolute times.
Definition: TimeStamp.h:61
Contains a system independet PRINTF macro.
Contains icl_core::thread::tMutex.
const TimeSpan timeout(1, 0)
Contains global LXRT functions.
Repesents absolute times.
Definition: TimeSpan.h:46
bool isThisLxrtTask()
Definition: os_lxrt.cpp:150
#define PRINTF
Contains icl_core::thread::RWLockImplLxrt35.
struct timespec systemTimespec() const
Definition: TimeBase.cpp:121


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58