process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
cross_process_sync.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voss <thomas.voss@canonical.com>
17  */
18 
19 #ifndef CORE_TESTING_CROSS_PROCESS_SYNC_H_
20 #define CORE_TESTING_CROSS_PROCESS_SYNC_H_
21 
22 #include <core/posix/visibility.h>
23 
24 #include <cstdint>
25 
26 #include <chrono>
27 #include <stdexcept>
28 
29 namespace core
30 {
31 namespace testing
32 {
37 {
38  public:
39  struct Error
40  {
41  Error() = delete;
42  ~Error() = delete;
43 
47  struct Timeout : public std::runtime_error
48  {
49  Timeout() : std::runtime_error("Timeout while waiting for event to happen.")
50  {
51  }
52  };
53  };
54 
59 
65 
69  ~CrossProcessSync() noexcept;
70 
76  CrossProcessSync& operator=(const CrossProcessSync& rhs);
77 
83  void try_signal_ready_for(const std::chrono::milliseconds& duration);
84 
91  std::uint32_t wait_for_signal_ready_for(const std::chrono::milliseconds& duration);
92 
93  private:
94  int fds[2];
95  std::uint32_t counter;
96 };
97 }
98 }
99 #endif // CORE_TESTING_CROSS_PROCESS_SYNC_H_
#define CORE_POSIX_DLL_PUBLIC
Definition: visibility.h:26
STL namespace.
A cross-process synchronization primitive that supports simple wait-condition-like scenarios...
Thrown if any of the *_for functions times out.