Commit fd172010 authored by Norisz Fay's avatar Norisz Fay
Browse files

Backed out 3 changesets (bug 1658072) as they are related to previously backed...

Backed out 3 changesets (bug 1658072) as they are related to previously backed out changeset CLOSED TREE

Backed out changeset 199d3ecfe13c (bug 1658072)
Backed out changeset a942be3d053d (bug 1658072)
Backed out changeset e0e98ee85f98 (bug 1658072)
parent 936d025f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -728,4 +728,9 @@ 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
+4 −0
Original line number Diff line number Diff line
@@ -543,6 +543,10 @@ 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)
};

+70 −0
Original line number Diff line number Diff line
@@ -262,6 +262,76 @@ 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!";
+45 −0
Original line number Diff line number Diff line
@@ -82,6 +82,48 @@ 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;
@@ -111,6 +153,9 @@ 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);
+9 −0
Original line number Diff line number Diff line
@@ -266,6 +266,15 @@ bool LaunchApp(const CommandLine& cl, const LaunchOptions&,
// Returns true if this is successful, false otherwise.
bool KillProcess(ProcessHandle process, int exit_code);

// Get the termination status (exit code) of the process and return true if the
// status indicates the process crashed. |child_exited| is set to true iff the
// child process has terminated. (|child_exited| may be NULL.)
//
// On Windows, it is an error to call this if the process hasn't terminated
// yet. On POSIX, |child_exited| is set correctly since we detect terminate in
// a different manner on POSIX.
bool DidProcessCrash(bool* child_exited, ProcessHandle handle);

}  // namespace base

namespace mozilla {
Loading