Android-cuttlefish cvd tool
sem.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <chrono>
19#include <optional>
20
23
24namespace cuttlefish::cvdalloc {
25
26constexpr std::chrono::seconds kSemNoTimeout = std::chrono::seconds(0);
27
28/*
29 * Write into the socket.
30 *
31 * Any other processes Wait'ing to read on the socket will be unblocked.
32 */
34
35/*
36 * Wait on the socket.
37 *
38 * The process wil block until the socket can be read from, the socket is
39 * shut down, or the timeout is reached. The Result is ok if the socket
40 * can be successfully read from.
41 */
42Result<void> Wait(SharedFD socket, std::chrono::seconds timeout);
43
44/*
45 * Like Wait, but also returns when a signal number can be read from signals.
46 *
47 * Returns that signal number, or nullopt if the socket was read instead.
48 */
49Result<std::optional<int>> Wait(SharedFD socket, std::chrono::seconds timeout,
50 SharedFD signals);
51
52} // namespace cuttlefish::cvdalloc
Definition: shared_fd.h:125
Definition: sem.cpp:33
constexpr std::chrono::seconds kSemNoTimeout
Definition: sem.h:26
Result< void > Wait(const SharedFD socket, std::chrono::seconds timeout)
Definition: sem.cpp:41
Result< void > Post(const SharedFD socket)
Definition: sem.cpp:35
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30