From: Davin McCall Date: Thu, 16 Jun 2016 22:54:54 +0000 (+0100) Subject: Yet another Dasynq update X-Git-Tag: v0.03~13 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=100650949c81204d8d52002e028aa8858a406bce;p=oweals%2Fdinit.git Yet another Dasynq update --- diff --git a/src/control.h b/src/control.h index f76ee28..a184039 100644 --- a/src/control.h +++ b/src/control.h @@ -47,7 +47,7 @@ extern int active_control_conns; class ServiceSet; class ServiceRecord; -class ControlConnWatcher : public BidiFdWatcher +class ControlConnWatcher : public EventLoop_t::BidiFdWatcher { inline Rearm receiveEvent(EventLoop_t * loop, int fd, int flags) noexcept; @@ -67,14 +67,14 @@ class ControlConnWatcher : public BidiFdWatcher void setWatchFlags(int flags) { - BidiFdWatcher::setWatchFlags(eventLoop, flags); + EventLoop_t::BidiFdWatcher::setWatchFlags(eventLoop, flags); } void registerWith(EventLoop_t *loop, int fd, int flags) { this->fd = fd; this->eventLoop = loop; - BidiFdWatcher::registerWith(loop, fd, flags); + BidiFdWatcher::registerWith(loop, fd, flags); } }; diff --git a/src/dasynq/dasynq.h b/src/dasynq/dasynq.h index 93ded31..d9b4b4a 100644 --- a/src/dasynq/dasynq.h +++ b/src/dasynq/dasynq.h @@ -74,22 +74,22 @@ enum class Rearm // TODO: add a REQUEUE option, which means, "I didn't complete input/output, run me again soon" }; - -// Forward declarations: -template class EventLoop; -template class FdWatcher; -template class BidiFdWatcher; -template class SignalWatcher; -template class ChildProcWatcher; - // Information about a received signal. // This is essentially a wrapper for the POSIX siginfo_t; its existence allows for mechanisms that receive // equivalent signal information in a different format (eg signalfd on Linux). using SigInfo = LoopTraits::SigInfo; +// Forward declarations: +template class EventLoop; + namespace dprivate { // (non-public API) - + + template class FdWatcher; + template class BidiFdWatcher; + template class SignalWatcher; + template class ChildProcWatcher; + enum class WatchType { SIGNAL, @@ -491,10 +491,10 @@ namespace dprivate { template class EventLoop { - friend class FdWatcher; - friend class BidiFdWatcher; - friend class SignalWatcher; - friend class ChildProcWatcher; + friend class dprivate::FdWatcher>; + friend class dprivate::BidiFdWatcher>; + friend class dprivate::SignalWatcher>; + friend class dprivate::ChildProcWatcher>; template using EventDispatch = dprivate::EventDispatch; template using waitqueue = dprivate::waitqueue; @@ -949,6 +949,13 @@ template class EventLoop public: + using mutex_t = T_Mutex; + + using FdWatcher = dprivate::FdWatcher>; + using BidiFdWatcher = dprivate::BidiFdWatcher>; + using SignalWatcher = dprivate::SignalWatcher>; + using ChildProcWatcher = dprivate::ChildProcWatcher>; + void run() noexcept { while (! processEvents()) { @@ -967,18 +974,20 @@ template class EventLoop } }; - typedef EventLoop NEventLoop; typedef EventLoop TEventLoop; // from dasync.cc: TEventLoop & getSystemLoop(); +namespace dprivate { + // Posix signal event watcher -template -class SignalWatcher : private dprivate::BaseSignalWatcher +template +class SignalWatcher : private dprivate::BaseSignalWatcher { using BaseWatcher = dprivate::BaseWatcher; + using T_Mutex = typename EventLoop::mutex_t; public: using SigInfo_p = typename dprivate::BaseSignalWatcher::SigInfo_p; @@ -986,14 +995,14 @@ public: // Register this watcher to watch the specified signal. // If an attempt is made to register with more than one event loop at // a time, behaviour is undefined. - inline void registerWatch(EventLoop *eloop, int signo) + inline void registerWatch(EventLoop *eloop, int signo) { BaseWatcher::init(); this->siginfo.set_signo(signo); eloop->registerSignal(this, signo); } - inline void deregisterWatch(EventLoop *eloop) noexcept + inline void deregisterWatch(EventLoop *eloop) noexcept { eloop->deregister(this, this->siginfo.get_signo()); } @@ -1002,10 +1011,11 @@ public: }; // Posix file descriptor event watcher -template -class FdWatcher : private dprivate::BaseFdWatcher +template +class FdWatcher : private dprivate::BaseFdWatcher { using BaseWatcher = dprivate::BaseWatcher; + using T_Mutex = typename EventLoop::mutex_t; protected: @@ -1033,7 +1043,7 @@ class FdWatcher : private dprivate::BaseFdWatcher // causes undefined behavior. // // Can fail with std::bad_alloc or std::system_error. - void registerWith(EventLoop *eloop, int fd, int flags) + void registerWith(EventLoop *eloop, int fd, int flags) { BaseWatcher::init(); this->watch_fd = fd; @@ -1050,12 +1060,12 @@ class FdWatcher : private dprivate::BaseFdWatcher // calling this method as long as the handler (if it is active) accesses no // internal state and returns Rearm::REMOVED. // TODO: implement REMOVED, or correct above statement. - void deregisterWatch(EventLoop *eloop) noexcept + void deregisterWatch(EventLoop *eloop) noexcept { eloop->deregister(this, this->watch_fd); } - void setEnabled(EventLoop *eloop, bool enable) noexcept + void setEnabled(EventLoop *eloop, bool enable) noexcept { std::lock_guard guard(eloop->getBaseLock()); eloop->setFdEnabled_nolock(this, this->watch_fd, this->watch_flags, enable); @@ -1070,12 +1080,13 @@ class FdWatcher : private dprivate::BaseFdWatcher // A Bi-directional file descriptor watcher with independent read- and write- channels. // This watcher type has two event notification methods which can both potentially be // active at the same time. -template -class BidiFdWatcher : private dprivate::BaseBidiFdWatcher +template +class BidiFdWatcher : private dprivate::BaseBidiFdWatcher { using BaseWatcher = dprivate::BaseWatcher; + using T_Mutex = typename EventLoop::mutex_t; - void setWatchEnabled(EventLoop *eloop, bool in, bool b) + void setWatchEnabled(EventLoop *eloop, bool in, bool b) { int events = in ? IN_EVENTS : OUT_EVENTS; @@ -1107,14 +1118,14 @@ class BidiFdWatcher : private dprivate::BaseBidiFdWatcher // TODO if a watch is disabled and currently queued, we should de-queue it. - void setInWatchEnabled(EventLoop *eloop, bool b) noexcept + void setInWatchEnabled(EventLoop *eloop, bool b) noexcept { eloop->getBaseLock().lock(); setWatchEnabled(eloop, true, b); eloop->getBaseLock().unlock(); } - void setOutWatchEnabled(EventLoop *eloop, bool b) noexcept + void setOutWatchEnabled(EventLoop *eloop, bool b) noexcept { eloop->getBaseLock().lock(); setWatchEnabled(eloop, false, b); @@ -1128,7 +1139,7 @@ class BidiFdWatcher : private dprivate::BaseBidiFdWatcher /// - unless the event loop will not be polled while the watcher is active. // (i.e. it is ok to call setWatchFlags from within the readReady/writeReady handlers if no other // thread will poll the event loop; it is ok to *dis*able a watcher that might be active). - void setWatchFlags(EventLoop * eloop, int newFlags) + void setWatchFlags(EventLoop * eloop, int newFlags) { std::lock_guard guard(eloop->getBaseLock()); if (LoopTraits::has_separate_rw_fd_watches) { @@ -1147,7 +1158,7 @@ class BidiFdWatcher : private dprivate::BaseBidiFdWatcher // can be any combination of dasynq::IN_EVENTS / dasynq::OUT_EVENTS. // // Can fail with std::bad_alloc or std::system_error. - void registerWith(EventLoop *eloop, int fd, int flags) + void registerWith(EventLoop *eloop, int fd, int flags) { BaseWatcher::init(); this->outWatcher.BaseWatcher::init(); @@ -1165,7 +1176,7 @@ class BidiFdWatcher : private dprivate::BaseBidiFdWatcher // calling this method as long as the handler (if it is active) accesses no // internal state and returns Rearm::REMOVED. // TODO: implement REMOVED, or correct above statement. - void deregisterWatch(EventLoop *eloop) noexcept + void deregisterWatch(EventLoop *eloop) noexcept { eloop->deregister(this, this->watch_fd); } @@ -1175,22 +1186,23 @@ class BidiFdWatcher : private dprivate::BaseBidiFdWatcher }; // Child process event watcher -template -class ChildProcWatcher : private dprivate::BaseChildWatcher +template +class ChildProcWatcher : private dprivate::BaseChildWatcher { using BaseWatcher = dprivate::BaseWatcher; + using T_Mutex = typename EventLoop::mutex_t; public: // Reserve resources for a child watcher with the given event loop. // Reservation can fail with std::bad_alloc. - void reserveWith(EventLoop *eloop) + void reserveWith(EventLoop *eloop) { eloop->reserveChildWatch(); } // Register a watcher for the given child process with an event loop. // Registration can fail with std::bad_alloc. - void registerWith(EventLoop *eloop, pid_t child) + void registerWith(EventLoop *eloop, pid_t child) { BaseWatcher::init(); this->watch_pid = child; @@ -1200,7 +1212,7 @@ class ChildProcWatcher : private dprivate::BaseChildWatcher // Register a watcher for the given child process with an event loop, // after having reserved resources previously (using reserveWith). // Registration cannot fail. - void registerReserved(EventLoop *eloop, pid_t child) noexcept + void registerReserved(EventLoop *eloop, pid_t child) noexcept { BaseWatcher::init(); eloop->registerReservedChild(this, child); @@ -1209,6 +1221,7 @@ class ChildProcWatcher : private dprivate::BaseChildWatcher // virtual void gotTermStat(EventLoop *, pid_t child, int status) = 0; }; +} // namespace dasynq::dprivate } // namespace dasynq #endif diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 07cfed8..43062f0 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -20,7 +20,7 @@ LogLevel log_level[2] = { LogLevel::WARN, LogLevel::WARN }; static ServiceSet *service_set = nullptr; // Reference to service set namespace { -class BufferedLogStream : public FdWatcher +class BufferedLogStream : public EventLoop_t::FdWatcher { private: diff --git a/src/dinit.cc b/src/dinit.cc index a87b4f7..7027cca 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -73,7 +73,7 @@ static void close_control_socket(EventLoop_t *loop) noexcept; static void control_socket_cb(EventLoop_t *loop, int fd); -class ControlSocketWatcher : public FdWatcher +class ControlSocketWatcher : public EventLoop_t::FdWatcher { Rearm gotEvent(EventLoop_t * loop, int fd, int flags) { @@ -88,7 +88,7 @@ class ControlSocketWatcher : public FdWatcher void registerWith(EventLoop_t * loop, int fd, int flags) { this->fd = fd; - FdWatcher::registerWith(loop, fd, flags); + EventLoop_t::FdWatcher::registerWith(loop, fd, flags); } }; @@ -133,7 +133,7 @@ const char * get_user_home() namespace { - class CallbackSignalHandler : public SignalWatcher + class CallbackSignalHandler : public EventLoop_t::SignalWatcher { public: typedef void (*cb_func_t)(EventLoop_t *); @@ -157,7 +157,7 @@ namespace { } }; - class ControlSocketWatcher : public FdWatcher + class ControlSocketWatcher : public EventLoop_t::FdWatcher { Rearm gotEvent(EventLoop_t * loop, int fd, int flags) { diff --git a/src/service.h b/src/service.h index f796581..27c6a37 100644 --- a/src/service.h +++ b/src/service.h @@ -180,7 +180,7 @@ static std::vector separate_args(std::string &s, std::list +class ServiceChildWatcher : public EventLoop_t::ChildProcWatcher { public: // TODO resolve clunkiness of storing this field @@ -190,7 +190,7 @@ class ServiceChildWatcher : public ChildProcWatcher ServiceChildWatcher(ServiceRecord * sr) noexcept : service(sr) { } }; -class ServiceIoWatcher : public FdWatcher +class ServiceIoWatcher : public EventLoop_t::FdWatcher { public: // TODO resolve clunkiness of storing these fields @@ -203,7 +203,7 @@ class ServiceIoWatcher : public FdWatcher void registerWith(EventLoop_t *loop, int fd, int flags) { this->fd = fd; - FdWatcher::registerWith(loop, fd, flags); + EventLoop_t::FdWatcher::registerWith(loop, fd, flags); } };