The Pedigree Project 0.1
timerfd-syscalls.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef POSIX_TIMERFD_SYSCALLS_H
3#define POSIX_TIMERFD_SYSCALLS_H
4
5#include "pedigree/kernel/compiler.h"
6#include "pedigree/kernel/process/ConditionVariable.h"
7#include "pedigree/kernel/process/Mutex.h"
8#include "pedigree/kernel/process/Readiness.h"
9#include "pedigree/kernel/utilities/SharedPointer.h"
10
11#include "descriptor-read.h"
12#include "posix-timer-state.h"
13
15class TimerFdService;
16
17namespace LinuxTimerFd {
18constexpr int NonBlock = 0x00000800;
19constexpr int CloseOnExec = 0x00080000;
20constexpr int Absolute = 1;
21constexpr int CancelOnSet = 2;
22constexpr size_t MaximumObjects = 256;
23} // namespace LinuxTimerFd
24
26class EXPORTED_PUBLIC TimerFd final : public ReadinessSource {
27 public:
28 explicit TimerFd(int clock);
29 ~TimerFd() override;
30
31 int readToUser(void* buffer, size_t count, bool canBlock);
32 int readWithCopy(size_t count, bool canBlock, PosixDescriptorReadCopy copy, void* context);
33 ReadyMask queryReady();
35 MUST_USE_RESULT bool addDescriptorOwner();
36 void removeDescriptorOwner();
37
38 private:
39 friend class TimerFdService;
40 friend int posix_timerfd_settime(int, int, const void*, void*);
41 friend int posix_timerfd_gettime(int, void*);
42
43 TimerFd(const TimerFd&) = delete;
44 TimerFd& operator=(const TimerFd&) = delete;
45
46 bool readable() const;
47 Time::Timestamp now(const PosixClockSnapshot& clock) const;
48 void update(const PosixClockSnapshot& clock);
49 uint64_t forward(PosixTimerState::State& state, Time::Timestamp current) const;
50 void service(uint64_t generation);
51 void changed();
52 int configure(int flags, Time::Timestamp value, Time::Timestamp interval, void* previous);
53 int getTime(void* value);
54
55 Mutex m_Lock;
56 ConditionVariable m_Readers;
58 ReadinessGenerations m_Generations;
59 uint64_t m_Counter;
60 uint64_t m_ClockGeneration;
61 size_t m_DescriptorOwners;
62 int m_Clock;
63 bool m_Expired;
64 bool m_CancelOnSet;
65 bool m_CancelPending;
66 bool m_CancelWake;
67 bool m_AdmissionOpen;
68};
69
70int posix_timerfd_create(int clock, int flags);
71int posix_timerfd_settime(int fd, int flags, const void* newValue, void* oldValue);
72int posix_timerfd_gettime(int fd, void* value);
73void posix_timerfd_clock_changed(uint64_t generation);
74
75#endif
Definition Mutex.h:56
virtual ReadinessGenerations readinessGenerations()
Definition Readiness.cc:177