| 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" | |
| 17 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/synchronization/condition_variable.h" | 18 #include "base/synchronization/condition_variable.h" |
| 20 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 21 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 22 #include "gpu/command_buffer/common/constants.h" | 21 #include "gpu/command_buffer/common/constants.h" |
| 23 #include "gpu/gpu_export.h" | 22 #include "gpu/gpu_export.h" |
| 24 | 23 |
| 25 namespace base { | 24 namespace base { |
| 26 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 130 } |
| 132 | 131 |
| 133 uint64_t fence_sync_release() { | 132 uint64_t fence_sync_release() { |
| 134 base::AutoLock auto_lock(fence_sync_lock_); | 133 base::AutoLock auto_lock(fence_sync_lock_); |
| 135 return fence_sync_release_; | 134 return fence_sync_release_; |
| 136 } | 135 } |
| 137 | 136 |
| 138 private: | 137 private: |
| 139 friend class base::RefCountedThreadSafe<SyncPointClientState>; | 138 friend class base::RefCountedThreadSafe<SyncPointClientState>; |
| 140 friend class SyncPointClient; | 139 friend class SyncPointClient; |
| 141 friend class SyncPointClientWaiter; | |
| 142 friend class SyncPointOrderData; | 140 friend class SyncPointOrderData; |
| 143 | 141 |
| 144 struct ReleaseCallback { | 142 struct ReleaseCallback { |
| 145 uint64_t release_count; | 143 uint64_t release_count; |
| 146 base::Closure callback_closure; | 144 base::Closure callback_closure; |
| 147 | 145 |
| 148 ReleaseCallback(uint64_t release, const base::Closure& callback); | 146 ReleaseCallback(uint64_t release, const base::Closure& callback); |
| 149 ~ReleaseCallback(); | 147 ~ReleaseCallback(); |
| 150 | 148 |
| 151 bool operator>(const ReleaseCallback& rhs) const { | 149 bool operator>(const ReleaseCallback& rhs) const { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // Keep the state that is sharable across multiple threads. | 225 // Keep the state that is sharable across multiple threads. |
| 228 scoped_refptr<SyncPointClientState> client_state_; | 226 scoped_refptr<SyncPointClientState> client_state_; |
| 229 | 227 |
| 230 // Unique namespace/client id pair for this sync point client. | 228 // Unique namespace/client id pair for this sync point client. |
| 231 const CommandBufferNamespace namespace_id_; | 229 const CommandBufferNamespace namespace_id_; |
| 232 const uint64_t client_id_; | 230 const uint64_t client_id_; |
| 233 | 231 |
| 234 DISALLOW_COPY_AND_ASSIGN(SyncPointClient); | 232 DISALLOW_COPY_AND_ASSIGN(SyncPointClient); |
| 235 }; | 233 }; |
| 236 | 234 |
| 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 context as a SyncPointClient, or else a | |
| 242 // deadlock could occur. Basically, SyncPointClientWaiter::Wait() should never | |
| 243 // be called between SyncPointOrderData::BeginProcessingOrderNumber() and | |
| 244 // SyncPointOrderData::FinishProcessingOrderNumber() on the same thread. | |
| 245 class GPU_EXPORT SyncPointClientWaiter { | |
| 246 public: | |
| 247 SyncPointClientWaiter() {} | |
| 248 ~SyncPointClientWaiter() {} | |
| 249 | |
| 250 bool Wait(SyncPointClientState* release_state, | |
| 251 uint64_t release_count, | |
| 252 const base::Closure& wait_complete_callback); | |
| 253 | |
| 254 bool WaitNonThreadSafe(SyncPointClientState* release_state, | |
| 255 uint64_t release_count, | |
| 256 scoped_refptr<base::SingleThreadTaskRunner> runner, | |
| 257 const base::Closure& wait_complete_callback); | |
| 258 | |
| 259 private: | |
| 260 DISALLOW_COPY_AND_ASSIGN(SyncPointClientWaiter); | |
| 261 }; | |
| 262 | |
| 263 // This class manages the sync points, which allow cross-channel | 235 // This class manages the sync points, which allow cross-channel |
| 264 // synchronization. | 236 // synchronization. |
| 265 class GPU_EXPORT SyncPointManager { | 237 class GPU_EXPORT SyncPointManager { |
| 266 public: | 238 public: |
| 267 explicit SyncPointManager(bool allow_threaded_wait); | 239 explicit SyncPointManager(bool allow_threaded_wait); |
| 268 ~SyncPointManager(); | 240 ~SyncPointManager(); |
| 269 | 241 |
| 270 // Creates/Destroy a sync point client which message processors should hold. | 242 // Creates/Destroy a sync point client which message processors should hold. |
| 271 scoped_ptr<SyncPointClient> CreateSyncPointClient( | 243 scoped_ptr<SyncPointClient> CreateSyncPointClient( |
| 272 scoped_refptr<SyncPointOrderData> order_data, | 244 scoped_refptr<SyncPointOrderData> order_data, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 SyncPointMap sync_point_map_; | 297 SyncPointMap sync_point_map_; |
| 326 uint32 next_sync_point_; | 298 uint32 next_sync_point_; |
| 327 base::ConditionVariable retire_cond_var_; | 299 base::ConditionVariable retire_cond_var_; |
| 328 | 300 |
| 329 DISALLOW_COPY_AND_ASSIGN(SyncPointManager); | 301 DISALLOW_COPY_AND_ASSIGN(SyncPointManager); |
| 330 }; | 302 }; |
| 331 | 303 |
| 332 } // namespace gpu | 304 } // namespace gpu |
| 333 | 305 |
| 334 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ | 306 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ |
| OLD | NEW |