Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Semaphore.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef _ALEXANDRIAKERNEL_SEMAPHORE_H
20#define _ALEXANDRIAKERNEL_SEMAPHORE_H
21
22#include <chrono>
23#include <memory>
24
25namespace Euclid {
26
31class Semaphore {
32public:
38 explicit Semaphore(unsigned int i);
39
44
48 void release();
49
53 void acquire();
54
59 bool try_acquire();
60
69 bool try_acquire_until(const std::chrono::system_clock::time_point& abs_time);
70
79 template <class Clock, class Duration>
81 return try_acquire_until(std::chrono::system_clock::now() + (Clock::now() - abs_time));
82 }
83
93 template <class Rep, class Ratio>
97
98private:
99 class SemaphoreImpl;
101};
102
103} // namespace Euclid
104
105#endif // _ALEXANDRIAKERNEL_SEMAPHORE_H
bool try_acquire_until(const std::chrono::time_point< Clock, Duration > &abs_time)
Definition Semaphore.h:80
bool try_acquire_for(const std::chrono::duration< Rep, Ratio > &rel_time)
Definition Semaphore.h:94
bool try_acquire_until(const std::chrono::system_clock::time_point &abs_time)
Definition Semaphore.cpp:44
std::unique_ptr< SemaphoreImpl > m_impl
Definition Semaphore.h:100