]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/thread/Condition.h
update download target update for octopus release
[ceph.git] / ceph / src / crimson / thread / Condition.h
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#pragma once
5
6#include <seastar/core/reactor.hh>
7#include <sys/eventfd.h>
8
9namespace ceph::thread {
10
11/// a synchronization primitive can be used to block a seastar thread, until
12/// another thread notifies it.
13class Condition {
14 seastar::file_desc file_desc;
15 int fd;
16 seastar::pollable_fd_state fd_state;
17 eventfd_t event = 0;
18public:
19 Condition()
20 : file_desc{seastar::file_desc::eventfd(0, 0)},
21 fd(file_desc.get()),
22 fd_state{std::move(file_desc)}
23 {}
24 seastar::future<> wait() {
25 return seastar::engine().read_some(fd_state, &event, sizeof(event))
26 .then([](size_t) {
27 return seastar::now();
28 });
29 }
30 void notify() {
31 eventfd_t result = 1;
32 ::eventfd_write(fd, result);
33 }
34};
35
36} // namespace ceph::thread