Bug 1658072 - Cleanup: remove the signal handling glue in the IPC event loop. r=nika

Now that we're no longer using libevent's signal handling, we don't need
an OO wrapper for it.

Differential Revision: https://phabricator.services.mozilla.com/D141311
This commit is contained in:
Jed Davis 2022-08-10 21:25:49 +00:00
Родитель fd0bcff6e5
Коммит 1dc9df1d11
6 изменённых файлов: 0 добавлений и 132 удалений

Просмотреть файл

@ -728,9 +728,4 @@ bool MessageLoopForIO::WatchFileDescriptor(int fd, bool persistent, Mode mode,
controller, delegate);
}
bool MessageLoopForIO::CatchSignal(int sig, SignalEvent* sigevent,
SignalWatcher* delegate) {
return pump_libevent()->CatchSignal(sig, sigevent, delegate);
}
#endif

Просмотреть файл

@ -543,10 +543,6 @@ class MessageLoopForIO : public MessageLoop {
FileDescriptorWatcher* controller,
Watcher* delegate);
typedef base::MessagePumpLibevent::SignalEvent SignalEvent;
typedef base::MessagePumpLibevent::SignalWatcher SignalWatcher;
bool CatchSignal(int sig, SignalEvent* sigevent, SignalWatcher* delegate);
#endif // defined(OS_POSIX)
};

Просмотреть файл

@ -262,76 +262,6 @@ void MessagePumpLibevent::OnLibeventNotification(int fd, short flags,
}
}
MessagePumpLibevent::SignalEvent::SignalEvent() : event_(NULL) {}
MessagePumpLibevent::SignalEvent::~SignalEvent() {
if (event_) {
StopCatching();
}
}
void MessagePumpLibevent::SignalEvent::Init(event* e) {
DCHECK(e);
DCHECK(event_ == NULL);
event_ = e;
}
bool MessagePumpLibevent::SignalEvent::StopCatching() {
// XXX/cjones: this code could be shared with
// FileDescriptorWatcher. ironic that libevent is "more"
// object-oriented than this C++
event* e = ReleaseEvent();
if (e == NULL) return true;
// event_del() is a no-op if the event isn't active.
int rv = event_del(e);
delete e;
return (rv == 0);
}
event* MessagePumpLibevent::SignalEvent::ReleaseEvent() {
event* e = event_;
event_ = NULL;
return e;
}
bool MessagePumpLibevent::CatchSignal(int sig, SignalEvent* sigevent,
SignalWatcher* delegate) {
DCHECK(sig > 0);
DCHECK(sigevent);
DCHECK(delegate);
// TODO if we want to support re-using SignalEvents, this code needs
// to jump through the same hoops as WatchFileDescriptor(). Not
// needed at present
DCHECK(NULL == sigevent->event_);
mozilla::UniquePtr<event> evt = mozilla::MakeUnique<event>();
signal_set(evt.get(), sig, OnLibeventSignalNotification, delegate);
if (event_base_set(event_base_, evt.get())) return false;
if (signal_add(evt.get(), NULL)) return false;
// Transfer ownership of evt to controller.
sigevent->Init(evt.release());
return true;
}
void MessagePumpLibevent::OnLibeventSignalNotification(int sig, short flags,
void* context) {
if (!awake_) {
profiler_thread_wake();
awake_ = true;
}
AUTO_PROFILER_LABEL("MessagePumpLibevent::OnLibeventSignalNotification",
OTHER);
DCHECK(sig > 0);
DCHECK(EV_SIGNAL == flags);
DCHECK(context);
reinterpret_cast<SignalWatcher*>(context)->OnSignal(sig);
}
// Reentrant!
void MessagePumpLibevent::Run(Delegate* delegate) {
DCHECK(keep_running_) << "Quit must have been called outside of Run!";

Просмотреть файл

@ -82,48 +82,6 @@ class MessagePumpLibevent : public MessagePump {
FileDescriptorWatcher* controller,
Watcher* delegate);
// This is analagous to FileDescriptorWatcher above, which really is
// just a wrapper around libevent's |struct event|. This class acts
// as a sort of "scoped event watcher" in that it guarantees that
// when this class is out of scope, the signal-event it wraps is
// removed from libevent's guts.
//
// XXX/cjones: this isn't my favorite API, but preserving it in
// order to match code above
class SignalEvent {
friend class MessagePumpLibevent;
public:
SignalEvent();
~SignalEvent(); // implicitly calls StopCatching()
// Have libevent forget this event.
bool StopCatching();
private:
void Init(event* e);
event* ReleaseEvent();
event* event_;
DISALLOW_COPY_AND_ASSIGN(SignalEvent);
};
class SignalWatcher {
public:
virtual ~SignalWatcher() {}
// Called from MessageLoop::Run when |sig| has been delivered to
// this process
virtual void OnSignal(int sig) = 0;
};
// Have the current thread's message loop catch the signal |sig|.
// Multiple watchers can catch the same signal; they're all notified
// upon its delivery. Callers must provide a preallocated
// SignalEvent object which can be used to manage the lifetime of
// this event. Returns true on success.
bool CatchSignal(int sig, SignalEvent* sigevent, SignalWatcher* delegate);
// MessagePump methods:
virtual void Run(Delegate* delegate) override;
virtual void Quit() override;
@ -153,9 +111,6 @@ class MessagePumpLibevent : public MessagePump {
// Called by libevent to tell us a registered FD can be read/written to.
static void OnLibeventNotification(int fd, short flags, void* context);
// Called by libevent upon receiving a signal
static void OnLibeventSignalNotification(int sig, short flags, void* context);
// Unix pipe used to implement ScheduleWork()
// ... callback; called by libevent inside Run() when pipe is ready to read
static void OnWakeup(int socket, short flags, void* context);

Просмотреть файл

@ -39,10 +39,6 @@ using namespace mozilla;
* This scheme is similar to using signalfd(), except it's portable and it
* doesn't require the use of sigprocmask, which is problematic because it
* masks signals received by child processes.
*
* In theory, we could use Chromium's MessageLoopForIO::CatchSignal() for this.
* But that uses libevent, which does not handle the realtime signals (bug
* 794074).
*/
// This is the write-end of a pipe that we use to notice when a

Просмотреть файл

@ -142,10 +142,6 @@ namespace {
* This scheme is similar to using signalfd(), except it's portable and it
* doesn't require the use of sigprocmask, which is problematic because it
* masks signals received by child processes.
*
* In theory, we could use Chromium's MessageLoopForIO::CatchSignal() for this.
* But that uses libevent, which does not handle the realtime signals (bug
* 794074).
*/
// It turns out that at least on some systems, SIGRTMIN is not a compile-time