mirror of https://gitee.com/bigwinds/arangodb
288 lines
11 KiB
C++
288 lines
11 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief dispatcher queue
|
|
///
|
|
/// @file
|
|
///
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2004-2013 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 Martin Schoenert
|
|
/// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef TRIAGENS_DISPATCHER_DISPATCHER_QUEUE_H
|
|
#define TRIAGENS_DISPATCHER_DISPATCHER_QUEUE_H 1
|
|
|
|
#include "Basics/Common.h"
|
|
|
|
#include "Basics/ConditionVariable.h"
|
|
#include "Dispatcher/Dispatcher.h"
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- forward declarations
|
|
// -----------------------------------------------------------------------------
|
|
|
|
namespace triagens {
|
|
namespace rest {
|
|
class DispatcherThread;
|
|
class Job;
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- class DispatcherQueue
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup Dispatcher
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief dispatcher queue
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class DispatcherQueue {
|
|
friend class Dispatcher;
|
|
friend class DispatcherThread;
|
|
|
|
private:
|
|
DispatcherQueue (DispatcherQueue const&);
|
|
DispatcherQueue& operator= (DispatcherQueue const&);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- constructors and destructors
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup Dispatcher
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
public:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief constructs a new dispatcher queue
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
DispatcherQueue (Dispatcher* dispatcher,
|
|
std::string const& name,
|
|
Dispatcher::newDispatcherThread_fptr,
|
|
size_t nrThreads);
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief destructor
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
~DispatcherQueue ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- public methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup Dispatcher
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
public:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief adds a job
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void addJob (Job*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief downgrades the thread to special
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void specializeThread (DispatcherThread*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief starts a queue
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool start ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief begins the shutdown sequence the queue
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void beginShutdown ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief shut downs the queue
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void shutdown ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief checks if the dispatcher queues are up and running
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool isStarted ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief is the queue still active
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool isRunning ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief starts a new queue thread
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool startQueueThread ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- private variables
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup Dispatcher
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
private:
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief name
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
string const _name;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief monopolistic jobs
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
basics::ConditionVariable _accessQueue;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief list of ready jobs
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
list<Job*> _readyJobs;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief queue is shutting down
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
volatile sig_atomic_t _stopping;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief monopolistic job
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
DispatcherThread * _monopolizer;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief list of started threads
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
set<DispatcherThread*> _startedThreads;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief list of stopped threads
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
list<DispatcherThread*> _stoppedThreads;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief number of started jobs
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t _nrStarted;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief number of threads that are up
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t _nrUp;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief number of running jobs
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t _nrRunning;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief number of waiting jobs
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t _nrWaiting;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief number of stopped jobs
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t _nrStopped;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief number of special jobs
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t _nrSpecial;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief total number of threads
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
size_t _nrThreads;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief dispatcher
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
Dispatcher* _dispatcher;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @brief thread creator function
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
Dispatcher::newDispatcherThread_fptr createDispatcherThread;
|
|
};
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#endif
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- END-OF-FILE
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Local Variables:
|
|
// mode: outline-minor
|
|
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
|
|
// End:
|