CARLA
 
载入中...
搜索中...
未找到
BufferPool.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/Buffer.h"
10
11#if defined(__clang__)
12# pragma clang diagnostic push
13# pragma clang diagnostic ignored "-Wold-style-cast"
14#endif
16#if defined(__clang__)
17# pragma clang diagnostic pop
18#endif
19
20#include <memory>
21
22namespace carla {
23
24 /// A pool of Buffer. Buffers popped from this pool automatically return to
25 /// the pool on destruction so the allocated memory can be reused.
26 ///
27 /// @warning Buffers adjust their size only by growing, they never shrink
28 /// unless explicitly cleared. The allocated memory is only deleted when this
29 /// pool is destroyed.
30 class BufferPool : public std::enable_shared_from_this<BufferPool> {
31 public:
32
33 BufferPool() = default;
34
35 explicit BufferPool(size_t estimated_size) : _queue(estimated_size) {}
36
37 /// Pop a Buffer from the queue, creates a new one if the queue is empty.
39 Buffer item;
40 _queue.try_dequeue(item); // we don't care if it fails.
41#if __cplusplus >= 201703L // C++17
42 item._parent_pool = weak_from_this();
43#else
44 item._parent_pool = shared_from_this();
45#endif
46 return item;
47 }
48
49 private:
50
51 friend class Buffer;
52
53 void Push(Buffer &&buffer) {
54 _queue.enqueue(std::move(buffer));
55 }
56
58 };
59
60} // namespace carla
A pool of Buffer.
Definition BufferPool.h:30
Buffer Pop()
Pop a Buffer from the queue, creates a new one if the queue is empty.
Definition BufferPool.h:38
BufferPool(size_t estimated_size)
Definition BufferPool.h:35
BufferPool()=default
void Push(Buffer &&buffer)
Definition BufferPool.h:53
moodycamel::ConcurrentQueue< Buffer > _queue
Definition BufferPool.h:57
A piece of raw data.
std::weak_ptr< BufferPool > _parent_pool
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133