OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 GPU_COMMAND_BUFFER_CLIENT_ATOMICOPS_H_ | 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_ATOMICOPS_H_ |
6 #define GPU_COMMAND_BUFFER_CLIENT_ATOMICOPS_H_ | 6 #define GPU_COMMAND_BUFFER_CLIENT_ATOMICOPS_H_ |
7 | 7 |
8 #include "../../gpu_export.h" | |
9 #include "../common/scoped_ptr.h" | |
10 #include "../common/types.h" | |
11 | |
8 namespace gpu { | 12 namespace gpu { |
9 | 13 |
10 void MemoryBarrier(); | 14 void MemoryBarrier(); |
11 | 15 |
16 class LockImpl; | |
17 class GPU_EXPORT Lock { | |
18 public: | |
19 Lock(); | |
20 ~Lock(); | |
21 void Acquire(); | |
22 void Release(); | |
23 bool Try(); | |
24 void AssertAcquired() const; | |
25 | |
26 private: | |
27 scoped_ptr<LockImpl> lock_; | |
28 | |
29 DISALLOW_COPY_AND_ASSIGN(Lock); | |
30 }; | |
31 | |
32 // A helper class that acquires the given Lock while the AutoLock is in scope. | |
33 class GPU_EXPORT AutoLock { | |
34 public: | |
35 explicit AutoLock(Lock& lock) : lock_(lock) { | |
36 lock_.Acquire(); | |
37 } | |
38 | |
39 ~AutoLock() { | |
40 lock_.AssertAcquired(); | |
apatrick_chromium
2012/03/29 21:03:58
What if another thread has the lock?
| |
41 lock_.Release(); | |
42 } | |
43 | |
44 private: | |
45 Lock& lock_; | |
46 DISALLOW_COPY_AND_ASSIGN(AutoLock); | |
47 }; | |
48 | |
12 } // namespace gpu | 49 } // namespace gpu |
13 | 50 |
14 #endif // GPU_COMMAND_BUFFER_CLIENT_ATOMICOPS_H_ | 51 #endif // GPU_COMMAND_BUFFER_CLIENT_ATOMICOPS_H_ |
OLD | NEW |