Apollo 10.0
自动驾驶开放平台
condition_notifier.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_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
27namespace apollo {
28namespace cyber {
29namespace transport {
30
31const uint32_t kBufLength = 4096;
32
34 struct Indicator {
35 std::atomic<uint64_t> next_seq = {0};
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
63 DECLARE_SINGLETON(ConditionNotifier)
64};
65
66} // namespace transport
67} // namespace cyber
68} // namespace apollo
69
70#endif // CYBER_TRANSPORT_SHM_CONDITION_NOTIFIER_H_
bool Listen(int timeout_ms, ReadableInfo *info) override
bool Notify(const ReadableInfo &info) override
#define DECLARE_SINGLETON(classname)
Definition macros.h:52
class register implement
Definition arena_queue.h:37