0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReferenceManager.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 
26 
27 #ifndef Hypertable_Master_ReferenceManager_h
28 #define Hypertable_Master_ReferenceManager_h
29 
31 
32 #include <mutex>
33 #include <unordered_map>
34 
35 namespace Hypertable {
36 
39 
42  public:
43 
49  bool add(OperationPtr operation) {
50  std::lock_guard<std::mutex> lock(m_mutex);
51  if (m_map.find(operation->id()) != m_map.end())
52  return false;
53  m_map[operation->id()] = operation;
54  return true;
55  }
56 
61  OperationPtr get(int64_t id) {
62  std::lock_guard<std::mutex> lock(m_mutex);
63  auto iter = m_map.find(id);
64  if (iter == m_map.end())
65  return 0;
66  return (*iter).second;
67  }
68 
71  void remove(OperationPtr operation) {
72  std::lock_guard<std::mutex> lock(m_mutex);
73  auto iter = m_map.find(operation->id());
74  if (iter != m_map.end())
75  m_map.erase(iter);
76  }
77 
80  void clear() {
81  std::lock_guard<std::mutex> lock(m_mutex);
82  m_map.clear();
83  }
84 
85  private:
86 
89 
91  std::unordered_map<int64_t, OperationPtr> m_map;
92  };
93 
95 
96 } // namespace Hypertable
97 
98 #endif // Hypertable_Master_ReferenceManager_h
static std::mutex mutex
Definition: Logger.cc:43
std::unordered_map< int64_t, OperationPtr > m_map
Reference map.
Declarations for Operation.
Holds references to operations that are to be manually removed.
Hypertable definitions
void clear()
Clears all referenced operations.
bool add(OperationPtr operation)
Adds an operation.
std::mutex m_mutex
Mutex for serializing concurrent access
std::shared_ptr< Operation > OperationPtr
Smart pointer to Operation.
Definition: Operation.h:609