Apollo  6.0
Open source self driving car software
base_map_pool.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 #pragma once
17 
18 #include <list>
19 #include <set>
20 
21 #include <boost/thread.hpp>
22 
23 #include "Eigen/Core"
24 
25 #include "cyber/task/task.h"
27 
28 namespace apollo {
29 namespace localization {
30 namespace msf {
31 namespace pyramid_map {
32 
35  public:
40  BaseMapNodePool(unsigned int pool_size, unsigned int thread_size);
42  virtual ~BaseMapNodePool();
47  void Initial(const BaseMapConfig* map_config, bool is_fixed_size = true);
49  void Release();
57  void FreeMapNode(BaseMapNode* map_node);
59  unsigned int GetPoolSize() { return pool_size_; }
60 
61  private:
65  void FreeMapNodeTask(BaseMapNode* map_node);
67  virtual BaseMapNode* AllocNewMapNode() = 0;
69  virtual void InitNewMapNode(BaseMapNode* node);
71  virtual void FinalizeMapNode(BaseMapNode* node);
73  virtual void DellocMapNode(BaseMapNode* node);
75  virtual void ResetMapNode(BaseMapNode* node);
76 
77  protected:
79  bool is_fixed_size_ = 0;
81  std::list<BaseMapNode*> free_list_;
83  std::set<BaseMapNode*> busy_nodes_;
85  unsigned int pool_size_ = 0;
87  std::future<void> node_reset_workers_;
89  boost::mutex mutex_;
91  const BaseMapConfig* map_config_ = nullptr;
92 };
93 
94 } // namespace pyramid_map
95 } // namespace msf
96 } // namespace localization
97 } // namespace apollo
void Initial(const BaseMapConfig *map_config, bool is_fixed_size=true)
Initialize the pool.
boost::mutex mutex_
The mutex for release thread.
Definition: base_map_pool.h:89
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
unsigned int pool_size_
The size of memory pool.
Definition: base_map_pool.h:85
BaseMapNode * AllocMapNode()
Get a MapNode object from memory pool.
const BaseMapConfig * map_config_
The mutex for release thread.
Definition: base_map_pool.h:91
unsigned int GetPoolSize()
Get the size of pool.
Definition: base_map_pool.h:59
std::set< BaseMapNode * > busy_nodes_
The set for used node.
Definition: base_map_pool.h:83
bool is_fixed_size_
The flag of pool auto expand.
Definition: base_map_pool.h:79
The memory pool for the data structure of BaseMapNode.
Definition: base_map_pool.h:34
The data structure of a Node in the map.
Definition: base_map_node.h:37
std::list< BaseMapNode * > free_list_
The list for free node.
Definition: base_map_pool.h:81
void FreeMapNode(BaseMapNode *map_node)
Release MapNode object to memory pool.
The options of the reflectance map.
Definition: base_map_config.h:42
std::future< void > node_reset_workers_
The thread pool for release node.
Definition: base_map_pool.h:87
BaseMapNodePool(unsigned int pool_size, unsigned int thread_size)
Constructor.