The Pedigree Project 0.1
eventfd-syscalls.h
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 */
8
9#ifndef EVENTFD_SYSCALLS_H
10#define EVENTFD_SYSCALLS_H
11
12#include "pedigree/kernel/Atomic.h"
13#include "pedigree/kernel/compiler.h"
14#include "pedigree/kernel/process/ConditionVariable.h"
15#include "pedigree/kernel/process/Mutex.h"
16#include "pedigree/kernel/process/Readiness.h"
17#include "pedigree/kernel/processor/types.h"
18
19namespace LinuxEventFd {
20constexpr int Semaphore = 0x00000001;
21constexpr int NonBlock = 0x00000800;
22constexpr int CloseOnExec = 0x00080000;
23} // namespace LinuxEventFd
24
26class EXPORTED_PUBLIC EventFd final : public ReadinessSource {
27 public:
28 EventFd(uint64_t initialValue, bool semaphoreMode);
29 ~EventFd() override;
30
32 int readValue(uint64_t& value, bool canBlock);
33
35 int writeValue(uint64_t value, bool canBlock);
36
38 ReadyMask queryReady();
39
41
43 uint64_t writeGeneration() const;
44
46 MUST_USE_RESULT bool addDescriptorOwner();
47 void removeDescriptorOwner();
48
49 private:
50 EventFd(const EventFd&) = delete;
51 EventFd& operator=(const EventFd&) = delete;
52
53 Mutex m_Lock;
54 ConditionVariable m_Readers;
55 ConditionVariable m_Writers;
56 uint64_t m_Counter;
57 Atomic<uint64_t> m_WriteGeneration;
58 ReadinessGenerations m_Generations;
59 size_t m_DescriptorOwners;
60 bool m_SemaphoreMode;
61 bool m_DescriptorAdmissionOpen;
62};
63
64int posix_eventfd(unsigned int initialValue);
65int posix_eventfd2(unsigned int initialValue, int flags);
66
67#endif
Definition Mutex.h:56
virtual ReadinessGenerations readinessGenerations()
Definition Readiness.cc:177