0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableMutatorQueue.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef Hypertable_Lib_TableMutatorQueue_h
23 #define Hypertable_Lib_TableMutatorQueue_h
24 
25 #include "ScanCells.h"
26 
28 
29 #include <Common/Thread.h>
30 
31 #include <condition_variable>
32 #include <list>
33 #include <mutex>
34 
35 namespace Hypertable {
36 
43 
44  public:
45 
49  TableMutatorQueue(std::mutex &mutex, std::condition_variable &cond) : m_mutex(mutex), m_cond(cond) { }
50 
52 
55  virtual void add(ApplicationHandler *app_handler) {
56  std::lock_guard<std::mutex> lock(m_mutex);
57  add_unlocked(app_handler);
58  }
59 
60  virtual void add_unlocked(ApplicationHandler *app_handler) {
61  m_work_queue.push_back(app_handler);
62  m_cond.notify_one();
63  }
64 
65  void wait_for_buffer(std::unique_lock<std::mutex> &lock, ApplicationHandler **app_handlerp) {
66  m_cond.wait(lock, [this](){ return !m_work_queue.empty();});
67  *app_handlerp = m_work_queue.front();
68  HT_ASSERT(*app_handlerp);
69  m_work_queue.pop_front();
70  }
71 
72  private:
73 
74  typedef std::list<ApplicationHandler *> WorkQueue;
76  std::condition_variable &m_cond;
77  WorkQueue m_work_queue;
78  };
79 
81  typedef std::shared_ptr<TableMutatorQueue> TableMutatorQueuePtr;
82 
83 }
84 
85 #endif // Hypertable_Lib_TableMutatorQueue_h
static std::mutex mutex
Definition: Logger.cc:43
std::shared_ptr< TableMutatorQueue > TableMutatorQueuePtr
Shared smart pointer to TableMutatorQueue.
virtual void add_unlocked(ApplicationHandler *app_handler)
Adds an application handler to queue without locking.
std::condition_variable & m_cond
#define HT_ASSERT(_e_)
Definition: Logger.h:396
TableMutatorQueue(std::mutex &mutex, std::condition_variable &cond)
virtual void add(ApplicationHandler *app_handler)
Adds an application handler to queue.
Importing boost::thread and boost::thread_group into the Hypertable namespace.
Provides application work queue and worker threads.
Hypertable definitions
void wait_for_buffer(std::unique_lock< std::mutex > &lock, ApplicationHandler **app_handlerp)
Base clase for application handlers.
Declarations for ApplicationQueueInterface.
std::list< ApplicationHandler * > WorkQueue
Abstract interface for application queue.