2 * Copyright (C) 2023 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
10 #include <common/exception.hpp>
11 #include <common/format.hpp>
12 #include <common/readwrite.hpp>
14 #include <sys/eventfd.h>
16 lttng::eventfd::eventfd(bool use_semaphore_semantics
, std::uint64_t initial_value
) :
17 file_descriptor([use_semaphore_semantics
, initial_value
]() {
18 int flags
= ::EFD_CLOEXEC
;
20 if (use_semaphore_semantics
) {
21 flags
|= ::EFD_SEMAPHORE
;
24 const auto raw_fd
= ::eventfd(initial_value
, flags
);
26 LTTNG_THROW_POSIX("Failed to create eventfd", errno
);
34 void lttng::eventfd::increment(std::uint64_t value
)
37 write(&value
, sizeof(value
));
38 } catch (const std::exception
& e
) {
39 LTTNG_THROW_ERROR(fmt::format("Failed to increment eventfd: {}", e
.what()));
43 std::uint64_t lttng::eventfd::decrement()
48 read(&value
, sizeof(value
));
49 } catch (const std::exception
& e
) {
50 LTTNG_THROW_ERROR(fmt::format("Failed to decrement eventfd: {}", e
.what()));
This page took 0.038667 seconds and 4 git commands to generate.