Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: base/task_scheduler/scheduler_lock.h

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H
6 #define BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H 6 #define BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H
7 7
8 #include <memory>
9
8 #include "base/base_export.h" 10 #include "base/base_export.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/synchronization/condition_variable.h" 12 #include "base/synchronization/condition_variable.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "base/task_scheduler/scheduler_lock_impl.h" 14 #include "base/task_scheduler/scheduler_lock_impl.h"
14 15
15 namespace base { 16 namespace base {
16 namespace internal { 17 namespace internal {
17 18
18 // SchedulerLock should be used anywhere a lock would be used in the scheduler. 19 // SchedulerLock should be used anywhere a lock would be used in the scheduler.
19 // When DCHECK_IS_ON(), lock checking occurs. Otherwise, SchedulerLock is 20 // When DCHECK_IS_ON(), lock checking occurs. Otherwise, SchedulerLock is
20 // equivalent to base::Lock. 21 // equivalent to base::Lock.
(...skipping 13 matching lines...) Expand all
34 // 35 //
35 // void Acquire() 36 // void Acquire()
36 // Acquires the lock. 37 // Acquires the lock.
37 // 38 //
38 // void Release() 39 // void Release()
39 // Releases the lock. 40 // Releases the lock.
40 // 41 //
41 // void AssertAcquired(). 42 // void AssertAcquired().
42 // DCHECKs if the lock is not acquired. 43 // DCHECKs if the lock is not acquired.
43 // 44 //
44 // scoped_ptr<ConditionVariable> CreateConditionVariable() 45 // std::unique_ptr<ConditionVariable> CreateConditionVariable()
45 // Creates a condition variable using this as a lock. 46 // Creates a condition variable using this as a lock.
46 47
47 #if DCHECK_IS_ON() 48 #if DCHECK_IS_ON()
48 class SchedulerLock : public SchedulerLockImpl { 49 class SchedulerLock : public SchedulerLockImpl {
49 public: 50 public:
50 SchedulerLock() = default; 51 SchedulerLock() = default;
51 explicit SchedulerLock(const SchedulerLock* predecessor) 52 explicit SchedulerLock(const SchedulerLock* predecessor)
52 : SchedulerLockImpl(predecessor) {} 53 : SchedulerLockImpl(predecessor) {}
53 }; 54 };
54 #else // DCHECK_IS_ON() 55 #else // DCHECK_IS_ON()
55 class SchedulerLock : public Lock { 56 class SchedulerLock : public Lock {
56 public: 57 public:
57 SchedulerLock() = default; 58 SchedulerLock() = default;
58 explicit SchedulerLock(const SchedulerLock*) {} 59 explicit SchedulerLock(const SchedulerLock*) {}
59 60
60 scoped_ptr<ConditionVariable> CreateConditionVariable() { 61 std::unique_ptr<ConditionVariable> CreateConditionVariable() {
61 return scoped_ptr<ConditionVariable>(new ConditionVariable(this)); 62 return std::unique_ptr<ConditionVariable>(new ConditionVariable(this));
62 } 63 }
63 }; 64 };
64 #endif // DCHECK_IS_ON() 65 #endif // DCHECK_IS_ON()
65 66
66 // Provides the same functionality as base::AutoLock for SchedulerLock. 67 // Provides the same functionality as base::AutoLock for SchedulerLock.
67 class AutoSchedulerLock { 68 class AutoSchedulerLock {
68 public: 69 public:
69 explicit AutoSchedulerLock(SchedulerLock& lock) : lock_(lock) { 70 explicit AutoSchedulerLock(SchedulerLock& lock) : lock_(lock) {
70 lock_.Acquire(); 71 lock_.Acquire();
71 } 72 }
72 73
73 ~AutoSchedulerLock() { 74 ~AutoSchedulerLock() {
74 lock_.AssertAcquired(); 75 lock_.AssertAcquired();
75 lock_.Release(); 76 lock_.Release();
76 } 77 }
77 78
78 private: 79 private:
79 SchedulerLock& lock_; 80 SchedulerLock& lock_;
80 81
81 DISALLOW_COPY_AND_ASSIGN(AutoSchedulerLock); 82 DISALLOW_COPY_AND_ASSIGN(AutoSchedulerLock);
82 }; 83 };
83 84
84 } // namespace internal 85 } // namespace internal
85 } // namespace base 86 } // namespace base
86 87
87 #endif // BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H 88 #endif // BASE_TASK_SCHEDULER_SCHEDULER_LOCK_H
OLDNEW
« no previous file with comments | « base/task_scheduler/priority_queue_unittest.cc ('k') | base/task_scheduler/scheduler_lock_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698