RWLockImplLxrt33.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 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
24 
26 #include <icl_core/os_lxrt.h>
27 
28 #include "icl_core_thread/Common.h"
29 
30 #undef STRICT_LXRT_CHECKS
31 
32 
33 namespace icl_core {
34 namespace thread {
35 
37  : m_rwlock(NULL)
38 {
39 #ifdef STRICT_LXRT_CHECKS
41  {
42  PRINTF("RWLockImplLxrt33::RWLockImplLxrt33: Called from a Linux task!\n");
43  return;
44  }
45 #endif
46  m_rwlock = new pthread_rwlock_t;
47  pthread_rwlock_init_rt(m_rwlock, NULL);
48 }
49 
51 {
52 #ifdef STRICT_LXRT_CHECKS
54  {
55  PRINTF("RWLockImplLxrt33::~RWLockImplLxrt33: Called from a Linux task!\n");
56  return;
57  }
58 #endif
59  if (m_rwlock)
60  {
61  pthread_rwlock_destroy_rt(m_rwlock);
62  delete m_rwlock;
63  m_rwlock = NULL;
64  }
65 }
66 
68 {
69 #ifdef STRICT_LXRT_CHECKS
71  {
72  PRINTF("RWLockImplLxrt33::readLock: Called from a Linux task!\n");
73  return false;
74  }
75 #endif
76  return pthread_rwlock_rdlock_rt(m_rwlock) == 0;
77 }
78 
80 {
81 #ifdef STRICT_LXRT_CHECKS
83  {
84  PRINTF("RWLockImplLxrt33::readLock: Called from a Linux task!\n");
85  return false;
86  }
87 #endif
88  struct timespec timeout_absolute_timespec = timeout.systemTimespec();
89  int ret = pthread_rwlock_timedrdlock_rt(m_rwlock, &timeout_absolute_timespec);
90  return (ret == 0);
91 }
92 
94 {
95 #ifdef STRICT_LXRT_CHECKS
97  {
98  PRINTF("RWLockImplLxrt33::readLock: Called from a Linux task!\n");
99  return false;
100  }
101 #endif
102  return readLock(impl::getAbsoluteTimeout(timeout));
103 }
104 
106 {
107 #ifdef STRICT_LXRT_CHECKS
109  {
110  PRINTF("RWLockImplLxrt33::tryReadLock: Called from a Linux task!\n");
111  return false;
112  }
113 #endif
114  int ret = pthread_rwlock_tryrdlock_rt(m_rwlock);
115  return (ret == 0);
116 }
117 
119 {
120 #ifdef STRICT_LXRT_CHECKS
122  {
123  PRINTF("RWLockImplLxrt33::writeLock: Called from a Linux task!\n");
124  return false;
125  }
126 #endif
127  return pthread_rwlock_wrlock_rt(m_rwlock) == 0;
128 }
129 
131 {
132 #ifdef STRICT_LXRT_CHECKS
134  {
135  PRINTF("RWLockImplLxrt33::writeLock: Called from a Linux task!\n");
136  return false;
137  }
138 #endif
139  struct timespec timeout_absolute_timespec = timeout.systemTimespec();
140  int ret = pthread_rwlock_timedwrlock_rt(m_rwlock, &timeout_absolute_timespec);
141  return (ret == 0);
142 }
143 
145 {
146 #ifdef STRICT_LXRT_CHECKS
148  {
149  PRINTF("RWLockImplLxrt33::writeLock: Called from a Linux task!\n");
150  return false;
151  }
152 #endif
153  return writeLock(impl::getAbsoluteTimeout(timeout));
154 }
155 
157 {
158 #ifdef STRICT_LXRT_CHECKS
160  {
161  PRINTF("RWLockImplLxrt33::tryWriteLock: Called from a Linux task!\n");
162  return false;
163  }
164 #endif
165  // ATTENTION: Calling pthread_rwlock_trywrlock_rt() while another
166  // thread holds a read lock seems to be buggy in RTAI 3.3, so the
167  // following does NOT work:
168  // int ret = pthread_rwlock_trywrlock_rt(rwlock);
169  // return (ret == 0);
170  // Therefore we call WriteLock() with a very short timeout!
171  static icl_core::TimeSpan try_write_lock_timeout(0, 1);
172  return writeLock(try_write_lock_timeout);
173 }
174 
176 {
177 #ifdef STRICT_LXRT_CHECKS
179  {
180  PRINTF("RWLockImplLxrt33::unlock: Called from a Linux task!\n");
181  return;
182  }
183 #endif
184  pthread_rwlock_unlock_rt(m_rwlock);
185 }
186 
187 }
188 }
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::RWLockImplLxrt33.
struct timespec systemTimespec() const
Definition: TimeBase.cpp:121


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