mirror of
https://github.com/hyprwm/aquamarine.git
synced 2024-11-17 09:35:59 +01:00
backend: idle fd improvements
This commit is contained in:
parent
04b2db8350
commit
874183997f
3 changed files with 22 additions and 9 deletions
|
@ -143,6 +143,7 @@ namespace Aquamarine {
|
||||||
} idle;
|
} idle;
|
||||||
|
|
||||||
void dispatchIdle();
|
void dispatchIdle();
|
||||||
|
void updateIdleTimer();
|
||||||
|
|
||||||
//
|
//
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -174,14 +174,17 @@ std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> Aquamarine::CBackend::ge
|
||||||
for (auto& i : implementations) {
|
for (auto& i : implementations) {
|
||||||
auto pollfds = i->pollFDs();
|
auto pollfds = i->pollFDs();
|
||||||
for (auto& p : pollfds) {
|
for (auto& p : pollfds) {
|
||||||
|
log(AQ_LOG_DEBUG, std::format("backend: poll fd {} for implementation {}", p->fd, backendTypeToName(i->type())));
|
||||||
result.emplace_back(p);
|
result.emplace_back(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& sfd : sessionFDs) {
|
for (auto& sfd : sessionFDs) {
|
||||||
|
log(AQ_LOG_DEBUG, std::format("backend: poll fd {} for session", sfd->fd));
|
||||||
result.emplace_back(sfd);
|
result.emplace_back(sfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log(AQ_LOG_DEBUG, std::format("backend: poll fd {} for idle", idle.fd));
|
||||||
result.emplace_back(makeShared<SPollFD>(idle.fd, [this]() { dispatchIdle(); }));
|
result.emplace_back(makeShared<SPollFD>(idle.fd, [this]() { dispatchIdle(); }));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -224,9 +227,15 @@ const std::vector<SP<IBackendImplementation>>& Aquamarine::CBackend::getImplemen
|
||||||
void Aquamarine::CBackend::addIdleEvent(SP<std::function<void(void)>> fn) {
|
void Aquamarine::CBackend::addIdleEvent(SP<std::function<void(void)>> fn) {
|
||||||
auto r = idle.pending.emplace_back(fn);
|
auto r = idle.pending.emplace_back(fn);
|
||||||
|
|
||||||
// update timerfd
|
updateIdleTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Aquamarine::CBackend::updateIdleTimer() {
|
||||||
|
uint64_t ADD_NS = idle.pending.empty() ? TIMESPEC_NSEC_PER_SEC * 240ULL /* 240s, 4 mins */ : 0;
|
||||||
|
|
||||||
timespec now;
|
timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
timespecAddNs(&now, ADD_NS);
|
||||||
|
|
||||||
itimerspec ts = {.it_value = now};
|
itimerspec ts = {.it_value = now};
|
||||||
|
|
||||||
|
@ -246,4 +255,6 @@ void Aquamarine::CBackend::dispatchIdle() {
|
||||||
if (i && *i)
|
if (i && *i)
|
||||||
(*i)();
|
(*i)();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateIdleTimer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,22 +147,23 @@ void Aquamarine::CHeadlessBackend::dispatchTimers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Aquamarine::CHeadlessBackend::updateTimerFD() {
|
void Aquamarine::CHeadlessBackend::updateTimerFD() {
|
||||||
long long lowest = 42069133769LL;
|
long long lowestNs = TIMESPEC_NSEC_PER_SEC * 240 /* 240s, 4 mins */;
|
||||||
const auto clocknow = std::chrono::steady_clock::now();
|
const auto clocknow = std::chrono::steady_clock::now();
|
||||||
|
bool any = false;
|
||||||
|
|
||||||
for (auto& t : timers.timers) {
|
for (auto& t : timers.timers) {
|
||||||
auto delta = std::chrono::duration_cast<std::chrono::microseconds>(t.when - clocknow).count();
|
auto delta = std::chrono::duration_cast<std::chrono::microseconds>(t.when - clocknow).count() * 1000 /* µs -> ns */;
|
||||||
|
|
||||||
if (delta < lowest)
|
if (delta < lowestNs)
|
||||||
lowest = delta;
|
lowestNs = delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lowest < 0)
|
if (lowestNs < 0)
|
||||||
lowest = 0;
|
lowestNs = 0;
|
||||||
|
|
||||||
timespec now;
|
timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
timespecAddNs(&now, lowest * 1000); // µs -> ns => * 1000
|
timespecAddNs(&now, lowestNs);
|
||||||
|
|
||||||
itimerspec ts = {.it_value = now};
|
itimerspec ts = {.it_value = now};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue