Apollo  6.0
Open source self driving car software
base_map_pool.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 
17 #pragma once
18 
19 #include <list>
20 #include <set>
21 
22 #include <boost/thread.hpp>
23 
24 #include "cyber/task/task.h"
26 
27 namespace apollo {
28 namespace localization {
29 namespace msf {
30 
33  public:
38  BaseMapNodePool(unsigned int pool_size, unsigned int thread_size);
40  virtual ~BaseMapNodePool();
45  void Initial(const BaseMapConfig* map_config, bool is_fixed_size = true);
47  void Release();
55  void FreeMapNode(BaseMapNode* map_node);
57  unsigned int GetPoolSize() { return pool_size_; }
58 
59  private:
63  void FreeMapNodeTask(BaseMapNode* map_node);
65  virtual BaseMapNode* AllocNewMapNode() = 0;
67  void InitNewMapNode(BaseMapNode* node);
69  void FinalizeMapNode(BaseMapNode* node);
71  void DellocMapNode(BaseMapNode* node);
73  void ResetMapNode(BaseMapNode* node);
74 
75  protected:
79  std::list<BaseMapNode*> free_list_;
81  std::set<BaseMapNode*> busy_nodes_;
83  unsigned int pool_size_;
85  std::future<void> node_reset_workers_;
87  boost::mutex mutex_;
90 };
91 
92 } // namespace msf
93 } // namespace localization
94 } // namespace apollo
bool is_fixed_size_
The flag of pool auto expand.
Definition: base_map_pool.h:77
unsigned int GetPoolSize()
Get the size of pool.
Definition: base_map_pool.h:57
The options of the reflectance map.
Definition: base_map_config.h:32
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void FreeMapNode(BaseMapNode *map_node)
Release MapNode object to memory pool.
unsigned int pool_size_
The size of memory pool.
Definition: base_map_pool.h:83
The memory pool for the data structure of BaseMapNode.
Definition: base_map_pool.h:32
std::future< void > node_reset_workers_
The thread pool for release node.
Definition: base_map_pool.h:85
const BaseMapConfig * map_config_
The mutex for release thread.
Definition: base_map_pool.h:89
BaseMapNode * AllocMapNode()
Get a MapNode object from memory pool.
void Initial(const BaseMapConfig *map_config, bool is_fixed_size=true)
Initialize the pool.
std::set< BaseMapNode * > busy_nodes_
The set for used node.
Definition: base_map_pool.h:81
boost::mutex mutex_
The mutex for release thread.
Definition: base_map_pool.h:87
std::list< BaseMapNode * > free_list_
The list for free node.
Definition: base_map_pool.h:79
The data structure of a Node in the map.
Definition: base_map_node.h:32
BaseMapNodePool(unsigned int pool_size, unsigned int thread_size)
Constructor.