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_SERVICE_SYNC_POINT_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 #include <queue> | 9 #include <queue> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/atomic_sequence_num.h" | 12 #include "base/atomic_sequence_num.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/synchronization/condition_variable.h" | 19 #include "base/synchronization/condition_variable.h" |
19 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
20 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
21 #include "gpu/command_buffer/common/constants.h" | 22 #include "gpu/command_buffer/common/constants.h" |
22 #include "gpu/gpu_export.h" | 23 #include "gpu/gpu_export.h" |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 131 } |
131 | 132 |
132 uint64_t fence_sync_release() { | 133 uint64_t fence_sync_release() { |
133 base::AutoLock auto_lock(fence_sync_lock_); | 134 base::AutoLock auto_lock(fence_sync_lock_); |
134 return fence_sync_release_; | 135 return fence_sync_release_; |
135 } | 136 } |
136 | 137 |
137 private: | 138 private: |
138 friend class base::RefCountedThreadSafe<SyncPointClientState>; | 139 friend class base::RefCountedThreadSafe<SyncPointClientState>; |
139 friend class SyncPointClient; | 140 friend class SyncPointClient; |
| 141 friend class SyncPointClientWaiter; |
140 friend class SyncPointOrderData; | 142 friend class SyncPointOrderData; |
141 | 143 |
142 struct ReleaseCallback { | 144 struct ReleaseCallback { |
143 uint64_t release_count; | 145 uint64_t release_count; |
144 base::Closure callback_closure; | 146 base::Closure callback_closure; |
145 | 147 |
146 ReleaseCallback(uint64_t release, const base::Closure& callback); | 148 ReleaseCallback(uint64_t release, const base::Closure& callback); |
147 ~ReleaseCallback(); | 149 ~ReleaseCallback(); |
148 | 150 |
149 bool operator>(const ReleaseCallback& rhs) const { | 151 bool operator>(const ReleaseCallback& rhs) const { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Keep the state that is sharable across multiple threads. | 227 // Keep the state that is sharable across multiple threads. |
226 scoped_refptr<SyncPointClientState> client_state_; | 228 scoped_refptr<SyncPointClientState> client_state_; |
227 | 229 |
228 // Unique namespace/client id pair for this sync point client. | 230 // Unique namespace/client id pair for this sync point client. |
229 const CommandBufferNamespace namespace_id_; | 231 const CommandBufferNamespace namespace_id_; |
230 const uint64_t client_id_; | 232 const uint64_t client_id_; |
231 | 233 |
232 DISALLOW_COPY_AND_ASSIGN(SyncPointClient); | 234 DISALLOW_COPY_AND_ASSIGN(SyncPointClient); |
233 }; | 235 }; |
234 | 236 |
| 237 // A SyncPointClientWaiter is a Sync Point Client which can only wait and on |
| 238 // fence syncs and not release any fence syncs itself. Because they cannot |
| 239 // release any fence syncs they do not need an associated order number since |
| 240 // deadlocks cannot happen. Note that it is important that this class does |
| 241 // not exist in the same execution thread as a SyncPointClient, or else a |
| 242 // deadlock could occur. |
| 243 class SyncPointClientWaiter { |
| 244 public: |
| 245 SyncPointClientWaiter(); |
| 246 ~SyncPointClientWaiter(); |
| 247 |
| 248 bool Wait(SyncPointClientState* release_state, |
| 249 uint64_t release_count, |
| 250 const base::Closure& wait_complete_callback); |
| 251 |
| 252 bool WaitNonThreadSafe(SyncPointClientState* release_state, |
| 253 uint64_t release_count, |
| 254 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 255 const base::Closure& wait_complete_callback); |
| 256 |
| 257 private: |
| 258 DISALLOW_COPY_AND_ASSIGN(SyncPointClientWaiter); |
| 259 }; |
| 260 |
235 // This class manages the sync points, which allow cross-channel | 261 // This class manages the sync points, which allow cross-channel |
236 // synchronization. | 262 // synchronization. |
237 class GPU_EXPORT SyncPointManager { | 263 class GPU_EXPORT SyncPointManager { |
238 public: | 264 public: |
239 explicit SyncPointManager(bool allow_threaded_wait); | 265 explicit SyncPointManager(bool allow_threaded_wait); |
240 ~SyncPointManager(); | 266 ~SyncPointManager(); |
241 | 267 |
242 // Creates/Destroy a sync point client which message processors should hold. | 268 // Creates/Destroy a sync point client which message processors should hold. |
243 scoped_ptr<SyncPointClient> CreateSyncPointClient( | 269 scoped_ptr<SyncPointClient> CreateSyncPointClient( |
244 scoped_refptr<SyncPointOrderData> order_data, | 270 scoped_refptr<SyncPointOrderData> order_data, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 SyncPointMap sync_point_map_; | 323 SyncPointMap sync_point_map_; |
298 uint32 next_sync_point_; | 324 uint32 next_sync_point_; |
299 base::ConditionVariable retire_cond_var_; | 325 base::ConditionVariable retire_cond_var_; |
300 | 326 |
301 DISALLOW_COPY_AND_ASSIGN(SyncPointManager); | 327 DISALLOW_COPY_AND_ASSIGN(SyncPointManager); |
302 }; | 328 }; |
303 | 329 |
304 } // namespace gpu | 330 } // namespace gpu |
305 | 331 |
306 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ | 332 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ |
OLD | NEW |