Apollo  6.0
Open source self driving car software
block.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_BLOCK_H_
18 #define CYBER_TRANSPORT_SHM_BLOCK_H_
19 
20 #include <atomic>
21 #include <cstdint>
22 
23 namespace apollo {
24 namespace cyber {
25 namespace transport {
26 
27 class Block {
28  friend class Segment;
29 
30  public:
31  Block();
32  virtual ~Block();
33 
34  uint64_t msg_size() const { return msg_size_; }
35  void set_msg_size(uint64_t msg_size) { msg_size_ = msg_size; }
36 
37  uint64_t msg_info_size() const { return msg_info_size_; }
39  msg_info_size_ = msg_info_size;
40  }
41 
42  static const int32_t kRWLockFree;
43  static const int32_t kWriteExclusive;
44  static const int32_t kMaxTryLockTimes;
45 
46  private:
47  bool TryLockForWrite();
48  bool TryLockForRead();
49  void ReleaseWriteLock();
50  void ReleaseReadLock();
51 
52  std::atomic<int32_t> lock_num_ = {0};
53 
54  uint64_t msg_size_;
55  uint64_t msg_info_size_;
56 };
57 
58 } // namespace transport
59 } // namespace cyber
60 } // namespace apollo
61 
62 #endif // CYBER_TRANSPORT_SHM_BLOCK_H_
void set_msg_info_size(uint64_t msg_info_size)
Definition: block.h:38
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
static const int32_t kRWLockFree
Definition: block.h:42
void set_msg_size(uint64_t msg_size)
Definition: block.h:35
uint64_t msg_size() const
Definition: block.h:34
static const int32_t kMaxTryLockTimes
Definition: block.h:44
Definition: segment.h:43
static const int32_t kWriteExclusive
Definition: block.h:43
Definition: block.h:27
uint64_t msg_info_size() const
Definition: block.h:37