MutexImplLxrt33.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 namespace icl_core {
33 namespace thread {
34 
36  : m_mutex(0)
37 {
38 #ifdef STRICT_LXRT_CHECKS
39  if (!icl_core::os::IsThisLxrtTask())
40  {
41  PRINTF("MutexImplLxrt33::MutexImplLxrt33: Called from a Linux task!\n");
42  return;
43  }
44 #endif
45  m_mutex = new pthread_mutex_t;
46  pthread_mutex_init_rt(m_mutex, NULL);
47 }
48 
50 {
51 #ifdef STRICT_LXRT_CHECKS
52  if (!icl_core::os::IsThisLxrtTask())
53  {
54  PRINTF("MutexImplLxrt33::~MutexImplLxrt33: Called from a Linux task!\n");
55  return;
56  }
57 #endif
58  if (m_mutex)
59  {
60  pthread_mutex_destroy_rt(m_mutex);
61  delete m_mutex;
62  m_mutex = 0;
63  }
64 }
65 
67 {
68 #ifdef STRICT_LXRT_CHECKS
70  {
71  PRINTF("MutexImplLxrt33::lock: Called from a Linux task!\n");
72  return false;
73  }
74 #endif
75  return pthread_mutex_lock_rt(m_mutex) == 0;
76 }
77 
79 {
80 #ifdef STRICT_LXRT_CHECKS
82  {
83  PRINTF("MutexImplLxrt33::lock: Called from a Linux task!\n");
84  return false;
85  }
86 #endif
87  return lock(impl::getAbsoluteTimeout(timeout));
88 }
89 
91 {
92 #ifdef STRICT_LXRT_CHECKS
94  {
95  PRINTF("MutexImplLxrt33::lock: Called from a Linux task!\n");
96  return false;
97  }
98 #endif
99  struct timespec timeout_absolute_timespec = timeout.systemTimespec();
100  bool ret = (pthread_mutex_timedlock_rt(m_mutex, & timeout_absolute_timespec) == 0);
101  return ret;
102 }
103 
105 {
106 #ifdef STRICT_LXRT_CHECKS
108  {
109  PRINTF("MutexImplLxrt33::tryLock: Called from a Linux task!\n");
110  return false;
111  }
112 #endif
113  bool ret = (pthread_mutex_trylock_rt(m_mutex) == 0);
114  return ret;
115 }
116 
118 {
119 #ifdef STRICT_LXRT_CHECKS
121  {
122  PRINTF("MutexImplLxrt33::unlock: Called from a Linux task!\n");
123  return;
124  }
125 #endif
126  pthread_mutex_unlock_rt(m_mutex);
127 }
128 
129 }
130 }
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
struct timespec systemTimespec() const
Definition: TimeBase.cpp:121
Contains icl_core::thread::MutexImplLxrt33.


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