2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
2013-08-06 23:25:57 +02:00
|
|
|
|
2018-08-22 15:33:16 +02:00
|
|
|
#ifndef EVENT_FD_HXX
|
|
|
|
#define EVENT_FD_HXX
|
2013-08-06 23:25:57 +02:00
|
|
|
|
2020-05-05 14:11:13 +02:00
|
|
|
#include "io/UniqueFileDescriptor.hxx"
|
2013-08-06 23:25:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A class that wraps eventfd().
|
|
|
|
*/
|
|
|
|
class EventFD {
|
2017-08-10 12:14:56 +02:00
|
|
|
UniqueFileDescriptor fd;
|
2013-08-06 23:25:57 +02:00
|
|
|
|
|
|
|
public:
|
2018-08-06 11:49:38 +02:00
|
|
|
/**
|
|
|
|
* Throws on error.
|
|
|
|
*/
|
2013-08-07 10:53:22 +02:00
|
|
|
EventFD();
|
2013-08-06 23:25:57 +02:00
|
|
|
|
2021-01-11 17:38:01 +01:00
|
|
|
FileDescriptor Get() const noexcept {
|
|
|
|
return fd;
|
2013-08-06 23:25:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if Write() was called at least once since the last
|
|
|
|
* Read() call.
|
|
|
|
*/
|
2018-08-06 11:57:40 +02:00
|
|
|
bool Read() noexcept;
|
2013-08-06 23:25:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wakes up the reader. Multiple calls to this function will
|
|
|
|
* be combined to one wakeup.
|
|
|
|
*/
|
2018-08-06 11:57:40 +02:00
|
|
|
void Write() noexcept;
|
2013-08-06 23:25:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|