Apollo  6.0
Open source self driving car software
condition_notifier.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_CONDITION_NOTIFIER_H_
18 #define CYBER_TRANSPORT_SHM_CONDITION_NOTIFIER_H_
19 
20 #include <sys/types.h>
21 #include <atomic>
22 #include <cstdint>
23 
24 #include "cyber/common/macros.h"
26 
27 namespace apollo {
28 namespace cyber {
29 namespace transport {
30 
31 const uint32_t kBufLength = 4096;
32 
34  struct Indicator {
35  std::atomic<uint64_t> next_seq = {0};
36  ReadableInfo infos[kBufLength];
37  uint64_t seqs[kBufLength] = {0};
38  };
39 
40  public:
41  virtual ~ConditionNotifier();
42 
43  void Shutdown() override;
44  bool Notify(const ReadableInfo& info) override;
45  bool Listen(int timeout_ms, ReadableInfo* info) override;
46 
47  static const char* Type() { return "condition"; }
48 
49  private:
50  bool Init();
51  bool OpenOrCreate();
52  bool OpenOnly();
53  bool Remove();
54  void Reset();
55 
56  key_t key_ = 0;
57  void* managed_shm_ = nullptr;
58  size_t shm_size_ = 0;
59  Indicator* indicator_ = nullptr;
60  uint64_t next_seq_ = 0;
61  std::atomic<bool> is_shutdown_ = {false};
62 
64 };
65 
66 } // namespace transport
67 } // namespace cyber
68 } // namespace apollo
69 
70 #endif // CYBER_TRANSPORT_SHM_CONDITION_NOTIFIER_H_
const uint32_t kBufLength
Definition: condition_notifier.h:31
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: readable_info.h:32
bool Notify(const ReadableInfo &info) override
Definition: notifier_base.h:31
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
bool Init(const char *binary_name)
bool Listen(int timeout_ms, ReadableInfo *info) override
static const char * Type()
Definition: condition_notifier.h:47
Definition: condition_notifier.h:33