Skip to content

Commit 7dc11e3

Browse files
Implemented Wrapper with HAVE_PPOLL
1 parent 4eff463 commit 7dc11e3

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

lldb/source/Host/posix/MainLoopPosix.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class MainLoopPosix::RunImpl {
9999
~RunImpl() = default;
100100

101101
Status Poll();
102+
int StartPoll(std::optional<MainLoopPosix::TimePoint> point);
102103
void ProcessReadEvents();
103104

104105
private:
@@ -159,6 +160,22 @@ MainLoopPosix::RunImpl::RunImpl(MainLoopPosix &loop) : loop(loop) {
159160
read_fds.reserve(loop.m_read_fds.size());
160161
}
161162

163+
int MainLoopPosix::RunImpl::StartPoll(
164+
std::optional<MainLoopPosix::TimePoint> point) {
165+
#if HAVE_PPOLL
166+
return ppoll(read_fds.data(), read_fds.size(), ToTimeSpec(point),
167+
/*sigmask=*/nullptr);
168+
#else
169+
using namespace std::chrono;
170+
int timeout = -1;
171+
if (point) {
172+
nanosecond dur = std::max(*point - steady_clock::now(), nanoseconds(0));
173+
timeout = ceil<milliseconds>(dur).count();
174+
}
175+
return poll(read_fds.data(), read_fds.size(), timeout);
176+
#endif
177+
}
178+
162179
Status MainLoopPosix::RunImpl::Poll() {
163180
read_fds.clear();
164181

@@ -169,24 +186,10 @@ Status MainLoopPosix::RunImpl::Poll() {
169186
pfd.revents = 0;
170187
read_fds.push_back(pfd);
171188
}
189+
int ready = StartPoll(loop.GetNextWakeupTime());
172190

173-
#if defined(_AIX)
174-
sigset_t origmask;
175-
int timeout;
176-
177-
timeout = -1;
178-
pthread_sigmask(SIG_SETMASK, nullptr, &origmask);
179-
int ready = poll(read_fds.data(), read_fds.size(), timeout);
180-
pthread_sigmask(SIG_SETMASK, &origmask, nullptr);
181191
if (ready == -1 && errno != EINTR)
182192
return Status(errno, eErrorTypePOSIX);
183-
#else
184-
if (ppoll(read_fds.data(), read_fds.size(),
185-
ToTimeSpec(loop.GetNextWakeupTime()),
186-
/*sigmask=*/nullptr) == -1 &&
187-
errno != EINTR)
188-
return Status(errno, eErrorTypePOSIX);
189-
#endif
190193

191194
return Status();
192195
}

0 commit comments

Comments
 (0)