Apollo 10.0
自动驾驶开放平台
bridge_buffer.cc
浏览该文件的文档.
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
18
19#include <memory.h>
20
21namespace apollo {
22namespace bridge {
23
24#define BRIDGE_IMPL(type) template class BridgeBuffer<type>
25
26template <typename T>
28
29template <typename T>
31 reset(size);
32}
33
34template <typename T>
36 std::lock_guard<std::mutex> lg(mutex_);
37 if (buf_) {
38 delete[] buf_;
39 }
40 buf_ = nullptr;
41 size_ = 0;
42 capacity_ = 0;
43}
44
45template <typename T>
47 return buf_;
48}
49
50template <typename T>
51void BridgeBuffer<T>::reset(size_t size) {
52 std::lock_guard<std::mutex> lg(mutex_);
53 if (capacity_ < size) {
54 if (buf_) {
55 delete[] buf_;
56 }
57 capacity_ = size;
58 buf_ = new T[capacity_];
59 }
60 size_ = size;
61 memset(buf_, 0, sizeof(T) * capacity_);
62}
63
64template <typename T>
65void BridgeBuffer<T>::write(size_t index, const T *data, size_t size) {
66 std::lock_guard<std::mutex> lg(mutex_);
67 reset(size + index);
68 T *p = buf_ + index;
69 memcpy(p, data, size);
70}
71
75
76} // namespace bridge
77} // namespace apollo
#define BRIDGE_IMPL(type)
void write(size_t index, const T *data, size_t size)
class register implement
Definition arena_queue.h:37