Chromium Code Reviews| Index: gpu/command_buffer/service/sync_point_manager.h |
| diff --git a/gpu/command_buffer/service/sync_point_manager.h b/gpu/command_buffer/service/sync_point_manager.h |
| index 98e849b76ced244c3400b171d12cf513c4f4f739..cf17ca0d873785a27e7523cb19cfeee742db4907 100644 |
| --- a/gpu/command_buffer/service/sync_point_manager.h |
| +++ b/gpu/command_buffer/service/sync_point_manager.h |
| @@ -7,15 +7,113 @@ |
| #include <vector> |
| +#include "base/atomic_sequence_num.h" |
| #include "base/callback.h" |
| #include "base/containers/hash_tables.h" |
| +#include "base/logging.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/synchronization/condition_variable.h" |
| #include "base/synchronization/lock.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "gpu/command_buffer/common/constants.h" |
| #include "gpu/gpu_export.h" |
| namespace gpu { |
| +class SyncPointClient; |
| +class SyncPointManager; |
| + |
| +class GPU_EXPORT SyncPointClientState |
| + : public base::RefCountedThreadSafe<SyncPointClientState> { |
| + public: |
| + SyncPointClientState(); |
| + |
| + uint32_t processed_order_num() const { |
| + return base::subtle::Acquire_Load(&processed_order_num_); |
| + } |
| + |
| + uint32_t unprocessed_order_num() const { |
| + return base::subtle::Acquire_Load(&unprocessed_order_num_); |
| + } |
| + |
| + protected: |
| + friend class base::RefCountedThreadSafe<SyncPointClientState>; |
| + friend class SyncPointClient; |
| + |
| + virtual ~SyncPointClientState(); |
| + |
| + void SetUnprocessedOrderNum(uint32_t order_num) { |
| + DCHECK_GT(order_num, unprocessed_order_num()); |
| + base::subtle::Release_Store(&unprocessed_order_num_, order_num); |
| + } |
| + |
| + void SetProcessedOrderNum(uint32_t order_num) { |
| + DCHECK_GT(order_num, processed_order_num()); |
| + base::subtle::Release_Store(&processed_order_num_, order_num); |
| + } |
| + |
| + // Last finished IPC order number. |
| + base::subtle::Atomic32 processed_order_num_; |
| + |
| + // Unprocessed order number expected to be processed under normal execution. |
| + base::subtle::Atomic32 unprocessed_order_num_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SyncPointClientState); |
| +}; |
| + |
| +class GPU_EXPORT SyncPointClient { |
| + public: |
| + ~SyncPointClient(); |
| + |
| + uint32_t GenerateUnprocessedOrderNumber(); |
| + |
| + void BeginProcessingOrderNumber(uint32_t order_num) { |
| + DCHECK(processing_thread_checker_.CalledOnValidThread()); |
| + |
| + DCHECK_GE(order_num, current_order_num_); |
| + current_order_num_ = order_num; |
| + } |
| + |
| + void FinishProcessingOrderNumber(uint32_t order_num) { |
| + DCHECK(processing_thread_checker_.CalledOnValidThread()); |
| + DCHECK_EQ(current_order_num_, order_num); |
| + client_state_->SetProcessedOrderNum(order_num); |
| + } |
| + |
| + scoped_refptr<SyncPointClientState> client_state() { return client_state_; } |
| + |
| + uint32_t current_order_num() const { |
| + DCHECK(processing_thread_checker_.CalledOnValidThread()); |
| + return current_order_num_; |
| + } |
| + |
| + private: |
| + friend class SyncPointManager; |
| + |
| + SyncPointClient(SyncPointManager* sync_point_manager, |
| + CommandBufferNamespace namespace_id, uint64_t client_id); |
| + |
| + protected: |
|
piman
2015/09/18 21:39:15
nit: order is public then protected then private.
David Yen
2015/09/18 22:39:59
Done, just placed everything in private.
|
| + // Sync point manager is guaranteed to exist in the lifetime of the client. |
| + SyncPointManager* sync_point_manager_; |
| + |
| + // Keep the state that is sharable across multiple threads. |
| + scoped_refptr<SyncPointClientState> client_state_; |
| + |
| + // Unique namespace/client id pair for this sync point client. |
| + CommandBufferNamespace namespace_id_; |
| + uint64_t client_id_; |
| + |
| + // Non thread-safe functions need to be called from a single thread. |
| + base::ThreadChecker processing_thread_checker_; |
| + |
| + // Current IPC order number being processed (only used on processing thread). |
| + uint32_t current_order_num_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SyncPointClient); |
| +}; |
| + |
| // This class manages the sync points, which allow cross-channel |
| // synchronization. |
| class GPU_EXPORT SyncPointManager { |
| @@ -23,6 +121,14 @@ class GPU_EXPORT SyncPointManager { |
| explicit SyncPointManager(bool allow_threaded_wait); |
| ~SyncPointManager(); |
| + // Creates/Destroy a sync point client which message processors should hold. |
| + scoped_ptr<SyncPointClient> CreateSyncPointClient( |
| + CommandBufferNamespace namespace_id, uint64_t client_id); |
| + |
| + // Finds the state of an already created sync point client. |
| + scoped_refptr<SyncPointClientState> GetSyncPointClientState( |
| + CommandBufferNamespace namespace_id, uint64_t client_id); |
| + |
| // Generates a sync point, returning its ID. This can me called on any thread. |
| // IDs start at a random number. Never return 0. |
| uint32 GenerateSyncPoint(); |
| @@ -44,14 +150,26 @@ class GPU_EXPORT SyncPointManager { |
| void WaitSyncPoint(uint32 sync_point); |
| private: |
| + friend class SyncPointClient; |
| + |
| typedef std::vector<base::Closure> ClosureList; |
| typedef base::hash_map<uint32, ClosureList> SyncPointMap; |
| - |
| + typedef base::hash_map<uint64_t, SyncPointClient*> ClientMap; |
| bool IsSyncPointRetiredLocked(uint32 sync_point); |
| + uint32_t GenerateOrderNumber(); |
|
piman
2015/09/18 21:39:15
I assume you will use this in GpuChannel as well,
David Yen
2015/09/18 22:39:59
Yes, I considered putting it in here since sunnyps
|
| + void DestroySyncPointClient(CommandBufferNamespace namespace_id, |
| + uint64_t client_id); |
| const bool allow_threaded_wait_; |
| + // Order number is global for all clients. |
| + base::AtomicSequenceNumber global_order_num_; |
| + |
| + // Client map holds a map of clients id to client for each namespace. |
| + base::Lock client_maps_lock_; |
| + ClientMap client_maps_[NUM_COMMAND_BUFFER_NAMESPACES]; |
| + |
| // Protects the 2 fields below. Note: callbacks shouldn't be called with this |
| // held. |
| base::Lock lock_; |