MutexImplLxrt35.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 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
26 
28 #include <icl_core/os_lxrt.h>
29 
30 #include "icl_core_thread/Common.h"
31 
32 #define STRICT_LXRT_CHECKS
33 
34 
35 namespace icl_core {
36 namespace thread {
37 
39  : m_mutex(0)
40 {
41 #ifdef STRICT_LXRT_CHECKS
43  {
44  PRINTF("MutexImplLxrt35::MutexImplLxrt35: Called from a Linux task!\n");
45  return;
46  }
47 #endif
48  m_mutex = new pthread_mutex_t;
49  pthread_mutex_init_rt(m_mutex, NULL);
50 }
51 
53 {
54 #ifdef STRICT_LXRT_CHECKS
56  {
57  PRINTF("MutexImplLxrt35::~MutexImplLxrt35: Called from a Linux task!\n");
58  return;
59  }
60 #endif
61  if (m_mutex)
62  {
63  pthread_mutex_destroy_rt(m_mutex);
64  delete m_mutex;
65  m_mutex = 0;
66  }
67 }
68 
70 {
71 #ifdef STRICT_LXRT_CHECKS
73  {
74  PRINTF("MutexImplLxrt35::lock: Called from a Linux task!\n");
75  return false;
76  }
77 #endif
78  return pthread_mutex_lock_rt(m_mutex) == 0;
79 }
80 
82 {
83 #ifdef STRICT_LXRT_CHECKS
85  {
86  PRINTF("MutexImplLxrt35::lock: Called from a Linux task!\n");
87  return false;
88  }
89 #endif
90  return lock(impl::getAbsoluteTimeout(timeout));
91 }
92 
94 {
95 #ifdef STRICT_LXRT_CHECKS
97  {
98  PRINTF("MutexImplLxrt35::lock: Called from a Linux task!\n");
99  return false;
100  }
101 #endif
102  struct timespec timeout_absolute_timespec = timeout.systemTimespec();
103  bool ret = (pthread_mutex_timedlock_rt(m_mutex, & timeout_absolute_timespec) == 0);
104  return ret;
105 }
106 
108 {
109 #ifdef STRICT_LXRT_CHECKS
111  {
112  PRINTF("MutexImplLxrt35::tryLock: Called from a Linux task!\n");
113  return false;
114  }
115 #endif
116  bool ret = (pthread_mutex_trylock_rt(m_mutex) == 0);
117  return ret;
118 }
119 
121 {
122 #ifdef STRICT_LXRT_CHECKS
124  {
125  PRINTF("MutexImplLxrt35::unlock: Called from a Linux task!\n");
126  return;
127  }
128 #endif
129  pthread_mutex_unlock_rt(m_mutex);
130 }
131 
132 }
133 }
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::MutexImplLxrt35.
struct timespec systemTimespec() const
Definition: TimeBase.cpp:121


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