Apollo 10.0
自动驾驶开放平台
state.h
浏览该文件的文档.
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#ifndef CYBER_TRANSPORT_SHM_STATE_H_
18#define CYBER_TRANSPORT_SHM_STATE_H_
19
20#include <atomic>
21#include <cstdint>
22#include <mutex>
23#include <string>
24
25namespace apollo {
26namespace cyber {
27namespace transport {
28
29class State {
30 public:
31 explicit State(const uint64_t& ceiling_msg_size);
32 virtual ~State();
33
35 uint32_t current_reference_count = reference_count_.load();
36 do {
37 if (current_reference_count == 0) {
38 return;
39 }
40 } while (!reference_count_.compare_exchange_strong(
41 current_reference_count, current_reference_count - 1));
42 }
43
44 void IncreaseReferenceCounts() { reference_count_.fetch_add(1); }
45
46 uint32_t FetchAddSeq(uint32_t diff) { return seq_.fetch_add(diff); }
47 uint32_t seq() { return seq_.load(); }
48
49 uint32_t FetchAddArenaSeq(uint32_t diff) {
50 return arena_seq_.fetch_add(diff);
51 }
52 uint32_t arena_seq() { return arena_seq_.load(); }
53
54 void set_need_remap(bool need) { need_remap_.store(need); }
55 bool need_remap() { return need_remap_; }
56
57 uint64_t ceiling_msg_size() { return ceiling_msg_size_.load(); }
58 uint32_t reference_counts() { return reference_count_.load(); }
59
60 private:
61 std::atomic<bool> need_remap_ = {false};
62 std::atomic<uint32_t> seq_ = {0};
63 std::atomic<uint32_t> arena_seq_ = {0};
64 std::atomic<uint32_t> reference_count_ = {0};
65 std::atomic<uint64_t> ceiling_msg_size_;
66};
67
68} // namespace transport
69} // namespace cyber
70} // namespace apollo
71
72#endif // CYBER_TRANSPORT_SHM_STATE_H_
uint32_t FetchAddArenaSeq(uint32_t diff)
Definition state.h:49
void set_need_remap(bool need)
Definition state.h:54
uint32_t FetchAddSeq(uint32_t diff)
Definition state.h:46
class register implement
Definition arena_queue.h:37