Apollo
10.0
自动驾驶开放平台
rw_lock_guard.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_BASE_RW_LOCK_GUARD_H_
18
#define CYBER_BASE_RW_LOCK_GUARD_H_
19
20
#include <unistd.h>
21
22
#include <atomic>
23
#include <condition_variable>
24
#include <cstdint>
25
#include <cstdlib>
26
#include <iostream>
27
#include <mutex>
28
#include <thread>
29
30
namespace
apollo
{
31
namespace
cyber {
32
namespace
base {
33
34
template
<
typename
RWLock>
35
class
ReadLockGuard
{
36
public
:
37
explicit
ReadLockGuard
(RWLock& lock) : rw_lock_(lock) { rw_lock_.ReadLock(); }
38
39
~ReadLockGuard
() { rw_lock_.ReadUnlock(); }
40
41
private
:
42
ReadLockGuard
(
const
ReadLockGuard
& other) =
delete
;
43
ReadLockGuard
& operator=(
const
ReadLockGuard
& other) =
delete
;
44
RWLock& rw_lock_;
45
};
46
47
template
<
typename
RWLock>
48
class
WriteLockGuard
{
49
public
:
50
explicit
WriteLockGuard
(RWLock& lock) : rw_lock_(lock) {
51
rw_lock_.WriteLock();
52
}
53
54
~WriteLockGuard
() { rw_lock_.WriteUnlock(); }
55
56
private
:
57
WriteLockGuard
(
const
WriteLockGuard
& other) =
delete
;
58
WriteLockGuard
& operator=(
const
WriteLockGuard
& other) =
delete
;
59
RWLock& rw_lock_;
60
};
61
62
}
// namespace base
63
}
// namespace cyber
64
}
// namespace apollo
65
66
#endif
// CYBER_BASE_RW_LOCK_GUARD_H_
apollo::cyber::base::ReadLockGuard
Definition
rw_lock_guard.h:35
apollo::cyber::base::ReadLockGuard::~ReadLockGuard
~ReadLockGuard()
Definition
rw_lock_guard.h:39
apollo::cyber::base::ReadLockGuard::ReadLockGuard
ReadLockGuard(RWLock &lock)
Definition
rw_lock_guard.h:37
apollo::cyber::base::WriteLockGuard
Definition
rw_lock_guard.h:48
apollo::cyber::base::WriteLockGuard::WriteLockGuard
WriteLockGuard(RWLock &lock)
Definition
rw_lock_guard.h:50
apollo::cyber::base::WriteLockGuard::~WriteLockGuard
~WriteLockGuard()
Definition
rw_lock_guard.h:54
apollo
class register implement
Definition
arena_queue.h:37
cyber
base
rw_lock_guard.h