RWLockImplLxrt38.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 
26 #include <rtai_posix.h>
27 
29 #include <icl_core/os_lxrt.h>
30 
31 #include "icl_core_thread/Common.h"
32 
33 #undef STRICT_LXRT_CHECKS
34 
35 
36 namespace icl_core {
37 namespace thread {
38 
40  : m_rwlock(NULL)
41 {
42 #ifdef STRICT_LXRT_CHECKS
44  {
45  PRINTF("RWLockImplLxrt38::RWLockImplLxrt38: Called from a Linux task!\n");
46  return;
47  }
48 #endif
49  m_rwlock = rt_typed_rwl_init(size_t(this), RESEM_RECURS);
50 }
51 
53 {
54 #ifdef STRICT_LXRT_CHECKS
56  {
57  PRINTF("RWLockImplLxrt38::~RWLockImplLxrt38: Called from a Linux task!\n");
58  return;
59  }
60 #endif
61  if (m_rwlock)
62  {
63  rt_rwl_delete(m_rwlock);
64  m_rwlock = NULL;
65  }
66 }
67 
69 {
70 #ifdef STRICT_LXRT_CHECKS
72  {
73  PRINTF("RWLockImplLxrt38::readLock: Called from a Linux task!\n");
74  return false;
75  }
76 #endif
77  return rt_rwl_rdlock(m_rwlock) == 0;
78 }
79 
81 {
82 #ifdef STRICT_LXRT_CHECKS
84  {
85  PRINTF("RWLockImplLxrt38::readLock: Called from a Linux task!\n");
86  return false;
87  }
88 #endif
89  struct timespec timeout_spec = timeout.systemTimespec();
90  int ret = rt_rwl_rdlock_until(m_rwlock, timespec2count(&timeout_spec));
91  return (ret == 0);
92 }
93 
95 {
96 #ifdef STRICT_LXRT_CHECKS
98  {
99  PRINTF("RWLockImplLxrt38::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("RWLockImplLxrt38::tryReadLock: Called from a Linux task!\n");
112  return false;
113  }
114 #endif
115  int ret = rt_rwl_rdlock_if(m_rwlock);
116  return (ret == 0);
117 }
118 
120 {
121 #ifdef STRICT_LXRT_CHECKS
123  {
124  PRINTF("RWLockImplLxrt38::writeLock: Called from a Linux task!\n");
125  return false;
126  }
127 #endif
128  return rt_rwl_wrlock(m_rwlock) == 0;
129 }
130 
132 {
133 #ifdef STRICT_LXRT_CHECKS
135  {
136  PRINTF("RWLockImplLxrt38::writeLock: Called from a Linux task!\n");
137  return false;
138  }
139 #endif
140  struct timespec timeout_spec = timeout.systemTimespec();
141  int ret = rt_rwl_wrlock_until(m_rwlock, timespec2count(&timeout_spec));
142  return (ret == 0);
143 }
144 
146 {
147 #ifdef STRICT_LXRT_CHECKS
149  {
150  PRINTF("RWLockImplLxrt38::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("RWLockImplLxrt38::tryWriteLock: Called from a Linux task!\n");
163  return false;
164  }
165 #endif
166  int ret = rt_rwl_wrlock_if(m_rwlock);
167  return ret == 0;
168  /*
169  // ATTENTION: Calling pthread_rwlock_trywrlock_rt() while another
170  // thread holds a read lock seems to be buggy in RTAI 3.3, so the
171  // following does NOT work:
172  // int ret = pthread_rwlock_trywrlock_rt(rwlock);
173  // return (ret == 0);
174  // Therefore we call WriteLock() with a very short timeout!
175  static icl_core::TimeSpan try_write_lock_timeout(0, 1);
176  return writeLock(try_write_lock_timeout);
177  */
178 }
179 
181 {
182 #ifdef STRICT_LXRT_CHECKS
184  {
185  PRINTF("RWLockImplLxrt38::unlock: Called from a Linux task!\n");
186  return;
187  }
188 #endif
189  rt_rwl_unlock(m_rwlock);
190 }
191 
192 }
193 }
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::RWLockImplLxrt38.
struct timespec systemTimespec() const
Definition: TimeBase.cpp:121


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