Main MRPT website > C++ reference for MRPT 1.5.9
CSemaphore.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #include "base-precomp.h" // Precompiled headers
11 
12 #include <mrpt/synch/CSemaphore.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::synch;
16 
18  unsigned int initialCount,
19  unsigned int maxCount)
20 {
21  m_count = initialCount;
22 }
23 
24 bool CSemaphore::waitForSignal( unsigned int timeout_ms )
25 {
27 
28  std::unique_lock<decltype(m_mutex)> lck(m_mutex);
29  while (m_count==0)
30  {
31  if (std::cv_status::timeout==m_condition.wait_for(lck, std::chrono::milliseconds(timeout_ms)))
32  return false;
33  }
34  --m_count;
35 
36  return true;
37 
38  MRPT_END
39 }
40 
41 void CSemaphore::release(unsigned int increaseCount )
42 {
44 
45  std::unique_lock<decltype(m_mutex)> lck(m_mutex);
46  ++m_count;
47  m_condition.notify_one();
48 
49  MRPT_END
50 }
bool waitForSignal(unsigned int timeout_ms=0)
Blocks until the count of the semaphore to be non-zero.
Definition: CSemaphore.cpp:24
#define MRPT_END
void release(unsigned int increaseCount=1)
Increments the count of the semaphore by a given amount.
Definition: CSemaphore.cpp:41
This namespace provides multitask, synchronization utilities.
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned long m_count
Definition: CSemaphore.h:36
GLsizei maxCount
Definition: glext.h:3902
std::condition_variable m_condition
Definition: CSemaphore.h:35
CSemaphore(unsigned int initialCount, unsigned int maxCount)
Creates a semaphore.
Definition: CSemaphore.cpp:17



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020