Apollo  6.0
Open source self driving car software
state.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 #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 
25 namespace apollo {
26 namespace cyber {
27 namespace transport {
28 
29 class 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  void set_need_remap(bool need) { need_remap_.store(need); }
50  bool need_remap() { return need_remap_; }
51 
52  uint64_t ceiling_msg_size() { return ceiling_msg_size_.load(); }
53  uint32_t reference_counts() { return reference_count_.load(); }
54 
55  private:
56  std::atomic<bool> need_remap_ = {false};
57  std::atomic<uint32_t> seq_ = {0};
58  std::atomic<uint32_t> reference_count_ = {0};
59  std::atomic<uint64_t> ceiling_msg_size_;
60 };
61 
62 } // namespace transport
63 } // namespace cyber
64 } // namespace apollo
65 
66 #endif // CYBER_TRANSPORT_SHM_STATE_H_
uint32_t seq()
Definition: state.h:47
void IncreaseReferenceCounts()
Definition: state.h:44
uint32_t FetchAddSeq(uint32_t diff)
Definition: state.h:46
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
uint64_t ceiling_msg_size()
Definition: state.h:52
Definition: state.h:29
State(const uint64_t &ceiling_msg_size)
void DecreaseReferenceCounts()
Definition: state.h:34
float diff(Image< float > *I, int x1, int y1, int x2, int y2)
Definition: segment_image.h:44
bool need_remap()
Definition: state.h:50
uint32_t reference_counts()
Definition: state.h:53
void set_need_remap(bool need)
Definition: state.h:49