Android-cuttlefish cvd tool
epoll.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 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
17#pragma once
18
19#include <sys/epoll.h>
20
21#include <memory>
22#include <optional>
23#include <set>
24#include <shared_mutex>
25
28
29namespace cuttlefish {
30
31struct EpollEvent {
33 uint32_t events;
34};
35
36class Epoll {
37 public:
38 static Result<Epoll> Create();
39 Epoll(); // Invalid instance
40 Epoll(Epoll&&);
42
43 Result<void> Add(SharedFD fd, uint32_t events);
44 Result<void> Modify(SharedFD fd, uint32_t events);
45 Result<void> AddOrModify(SharedFD fd, uint32_t events);
48
49 private:
51
61 std::shared_mutex epoll_mutex_;
67 std::shared_mutex watched_mutex_;
68 std::set<SharedFD> watched_;
69};
70
71} // namespace cuttlefish
Definition: expected.h:86
Definition: epoll.h:36
Epoll & operator=(Epoll &&)
Definition: epoll.cpp:57
SharedFD epoll_fd_
Definition: epoll.h:62
static Result< Epoll > Create()
Definition: epoll.cpp:33
std::shared_mutex epoll_mutex_
Definition: epoll.h:61
Result< void > Delete(SharedFD fd)
Definition: epoll.cpp:130
Result< void > AddOrModify(SharedFD fd, uint32_t events)
Definition: epoll.cpp:92
Result< void > Modify(SharedFD fd, uint32_t events)
Definition: epoll.cpp:111
Result< std::optional< EpollEvent > > Wait()
Definition: epoll.cpp:147
std::set< SharedFD > watched_
Definition: epoll.h:68
Result< void > Add(SharedFD fd, uint32_t events)
Definition: epoll.cpp:69
std::shared_mutex watched_mutex_
Definition: epoll.h:67
Definition: shared_fd.h:129
Definition: alloc_utils.cpp:23
Definition: epoll.h:31
uint32_t events
Definition: epoll.h:33
SharedFD fd
Definition: epoll.h:32