//////////////////////////////////////////////////////////////////////////////// /// @brief input-output scheduler using libev /// /// @file /// /// DISCLAIMER /// /// Copyright 2010-2011 triagens GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Dr. Frank Celler /// @author Achim Brandt /// @author Copyright 2008-2011, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #ifndef TRIAGENS_FYN_SCHEDULER_SCHEDULER_LIBEV_H #define TRIAGENS_FYN_SCHEDULER_SCHEDULER_LIBEV_H 1 #include "Scheduler/SchedulerImpl.h" #include namespace triagens { namespace rest { //////////////////////////////////////////////////////////////////////////////// /// @brief input-output scheduler using libev //////////////////////////////////////////////////////////////////////////////// class SchedulerLibev : public SchedulerImpl { public: //////////////////////////////////////////////////////////////////////////////// /// @brief returns the available backends //////////////////////////////////////////////////////////////////////////////// static int availableBackends (); public: //////////////////////////////////////////////////////////////////////////////// /// @brief creates a scheduler //////////////////////////////////////////////////////////////////////////////// explicit SchedulerLibev (size_t nrThreads = 1, int backend = BACKEND_AUTO); //////////////////////////////////////////////////////////////////////////////// /// @brief deletes a scheduler //////////////////////////////////////////////////////////////////////////////// ~SchedulerLibev (); public: //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void eventLoop (EventLoop); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void wakeupLoop (EventLoop); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// EventToken installSocketEvent (EventLoop, EventType, Task*, socket_t); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void startSocketEvents (EventToken); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void stopSocketEvents (EventToken); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// EventToken installAsyncEvent (EventLoop, Task*); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void sendAsync (EventToken); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// EventToken installTimerEvent (EventLoop, Task*, double timeout); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void clearTimer (EventToken); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void rearmTimer (EventToken, double timeout); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// EventToken installPeriodicEvent (EventLoop, Task*, double offset, double intervall); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void rearmPeriodic (EventToken, double offset, double timeout); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// EventToken installSignalEvent (EventLoop, Task*, int signal); //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void uninstallEvent (EventToken); private: void* lookupWatcher (EventToken); void* lookupWatcher (EventToken, EventType&); void* lookupLoop (EventLoop); EventToken registerWatcher (void*, EventType); void unregisterWatcher (EventToken); private: int _backend; void* _loops; void* _wakers; basics::Mutex _watcherLock; vector _watchers; vector _frees; map _types; }; } } #endif