21 #include <system_error> 28 const int read_fd = 0;
29 const int write_fd = 1;
35 throw std::system_error(errno, std::system_category());
40 fds[0] = ::dup(rhs.fds[0]);
41 fds[1] = ::dup(rhs.fds[1]);
54 fds[0] = ::dup(rhs.fds[0]);
55 fds[1] = ::dup(rhs.fds[1]);
57 counter = rhs.counter;
64 static const short empty_revents = 0;
65 pollfd poll_fd[1] = { { fds[write_fd], POLLOUT, empty_revents } };
68 if ((rc = ::poll(poll_fd, 1, duration.count())) < 0)
69 throw std::system_error(errno, std::system_category());
73 static const std::uint32_t value = 1;
74 if (
sizeof(value) != write(fds[write_fd], std::addressof(value),
sizeof(value)))
75 throw std::system_error(errno, std::system_category());
80 static const short empty_revents = 0;
81 pollfd poll_fd[1] = { { fds[read_fd], POLLIN, empty_revents } };
84 if ((rc = ::poll(poll_fd, 1, duration.count())) < 0)
85 throw std::system_error(errno, std::system_category());
89 std::uint32_t value = 0;
90 if (
sizeof(value) != read(fds[read_fd], std::addressof(value),
sizeof(value)))
91 throw std::system_error(errno, std::system_category());
94 throw std::system_error(errno, std::system_category());
CrossProcessSync & operator=(const CrossProcessSync &rhs)
operator =, dup's the underlying fds.
A cross-process synchronization primitive that supports simple wait-condition-like scenarios...
~CrossProcessSync() noexcept
Closes the underlying fds.
void try_signal_ready_for(const std::chrono::milliseconds &duration)
Try to signal the other side that we are ready for at most duration milliseconds. ...
CrossProcessSync()
Constructs a new sync element.
std::uint32_t wait_for_signal_ready_for(const std::chrono::milliseconds &duration)
Wait for the other sides to signal readiness for at most duration milliseconds.
Thrown if any of the *_for functions times out.