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 #include "gpu/command_buffer/service/sync_point_manager.h" | 5 #include "gpu/command_buffer/service/sync_point_manager.h" |
6 | 6 |
7 #include <climits> | 7 #include <climits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "base/sequence_checker.h" | 11 #include "base/sequence_checker.h" |
12 | 12 |
13 namespace gpu { | 13 namespace gpu { |
14 | 14 |
15 static const int kMaxSyncBase = INT_MAX; | 15 static const int kMaxSyncBase = INT_MAX; |
16 | 16 |
17 uint32_t SyncPointClient::GenerateUnprocessedOrderNumber() { | |
18 DCHECK(sync_point_manager_); | |
19 const uint32_t order_num = sync_point_manager_->GenerateOrderNumber(); | |
20 base::subtle::Release_Store(&unprocessed_order_num_, order_num); | |
21 return order_num; | |
22 } | |
23 | |
24 SyncPointClient::SyncPointClient(SyncPointManager* sync_point_manager, | |
25 SyncPointNamespace namespace_id, | |
26 uint64_t client_id) | |
27 : sync_point_manager_(sync_point_manager), | |
28 namespace_id_(namespace_id), | |
29 client_id_(client_id), | |
30 current_order_num_(0), | |
31 processed_order_num_(0), | |
32 unprocessed_order_num_(0) { | |
33 processing_thread_checker_.DetachFromThread(); | |
piman
2015/09/15 23:47:15
Do you need this? I would think the same thread th
David Yen
2015/09/18 18:43:59
Removed.
| |
34 } | |
35 | |
36 void SyncPointClient::Destroy() { | |
37 sync_point_manager_ = nullptr; | |
38 } | |
39 | |
40 SyncPointClient::~SyncPointClient() { | |
41 DCHECK(!IsValid()); | |
42 } | |
43 | |
17 SyncPointManager::SyncPointManager(bool allow_threaded_wait) | 44 SyncPointManager::SyncPointManager(bool allow_threaded_wait) |
18 : allow_threaded_wait_(allow_threaded_wait), | 45 : allow_threaded_wait_(allow_threaded_wait), |
19 // To reduce the risk that a sync point created in a previous GPU process | 46 // To reduce the risk that a sync point created in a previous GPU process |
20 // will be in flight in the next GPU process, randomize the starting sync | 47 // will be in flight in the next GPU process, randomize the starting sync |
21 // point number. http://crbug.com/373452 | 48 // point number. http://crbug.com/373452 |
22 next_sync_point_(base::RandInt(1, kMaxSyncBase)), | 49 next_sync_point_(base::RandInt(1, kMaxSyncBase)), |
23 retire_cond_var_(&lock_) {} | 50 retire_cond_var_(&lock_) { |
51 global_order_num_.GetNext(); | |
52 } | |
24 | 53 |
25 SyncPointManager::~SyncPointManager() {} | 54 SyncPointManager::~SyncPointManager() { |
55 for (int i = 0; i < NUM_SYNC_POINT_NAMESPACES; ++i) { | |
56 DCHECK(client_maps_[i].empty()); | |
57 } | |
58 } | |
59 | |
60 scoped_refptr<SyncPointClient> SyncPointManager::CreateSyncPointClient( | |
61 SyncPointNamespace namespace_id, uint64_t client_id) { | |
62 DCHECK(namespace_id >= 0 && namespace_id < NUM_SYNC_POINT_NAMESPACES); | |
63 base::AutoLock auto_lock(client_maps_lock_); | |
64 | |
65 ClientMap& client_map = client_maps_[namespace_id]; | |
66 std::pair<ClientMap::iterator, bool> result = client_map.insert( | |
67 std::make_pair(client_id, new SyncPointClient(this, | |
68 namespace_id, | |
69 client_id))); | |
70 DCHECK(result.second); | |
71 | |
72 return result.first->second; | |
73 } | |
74 | |
75 void SyncPointManager::DestroySyncPointClient( | |
76 scoped_refptr<SyncPointClient> client) { | |
77 const SyncPointNamespace namespace_id = client->namespace_id_; | |
78 const uint32_t client_id = client->client_id_; | |
79 DCHECK(namespace_id >= 0 && namespace_id < NUM_SYNC_POINT_NAMESPACES); | |
80 base::AutoLock auto_lock(client_maps_lock_); | |
81 ClientMap& client_map = client_maps_[namespace_id]; | |
82 ClientMap::iterator it = client_map.find(client_id); | |
83 DCHECK(it != client_map.end()); | |
84 it->second->Destroy(); | |
piman
2015/09/15 23:47:15
nit: no need to do this under the lock. you can ju
David Yen
2015/09/18 18:43:59
Done.
| |
85 client_map.erase(it); | |
86 } | |
87 | |
88 scoped_refptr<SyncPointClient> SyncPointManager::GetSyncPointClient( | |
89 SyncPointNamespace namespace_id, uint64_t client_id) { | |
90 DCHECK(namespace_id >= 0 && namespace_id < NUM_SYNC_POINT_NAMESPACES); | |
91 base::AutoLock auto_lock(client_maps_lock_); | |
92 | |
93 ClientMap& client_map = client_maps_[namespace_id]; | |
94 ClientMap::iterator it = client_map.find(client_id); | |
95 if (it != client_map.end()) { | |
96 return it->second; | |
97 } | |
98 return nullptr; | |
99 } | |
26 | 100 |
27 uint32 SyncPointManager::GenerateSyncPoint() { | 101 uint32 SyncPointManager::GenerateSyncPoint() { |
28 base::AutoLock lock(lock_); | 102 base::AutoLock lock(lock_); |
29 uint32 sync_point = next_sync_point_++; | 103 uint32 sync_point = next_sync_point_++; |
30 // When an integer overflow occurs, don't return 0. | 104 // When an integer overflow occurs, don't return 0. |
31 if (!sync_point) | 105 if (!sync_point) |
32 sync_point = next_sync_point_++; | 106 sync_point = next_sync_point_++; |
33 | 107 |
34 // Note: wrapping would take days for a buggy/compromized renderer that would | 108 // Note: wrapping would take days for a buggy/compromized renderer that would |
35 // insert sync points in a loop, but if that were to happen, better explicitly | 109 // insert sync points in a loop, but if that were to happen, better explicitly |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 while (!IsSyncPointRetiredLocked(sync_point)) { | 162 while (!IsSyncPointRetiredLocked(sync_point)) { |
89 retire_cond_var_.Wait(); | 163 retire_cond_var_.Wait(); |
90 } | 164 } |
91 } | 165 } |
92 | 166 |
93 bool SyncPointManager::IsSyncPointRetiredLocked(uint32 sync_point) { | 167 bool SyncPointManager::IsSyncPointRetiredLocked(uint32 sync_point) { |
94 lock_.AssertAcquired(); | 168 lock_.AssertAcquired(); |
95 return sync_point_map_.find(sync_point) == sync_point_map_.end(); | 169 return sync_point_map_.find(sync_point) == sync_point_map_.end(); |
96 } | 170 } |
97 | 171 |
172 uint32_t SyncPointManager::GenerateOrderNumber() { | |
173 return global_order_num_.GetNext(); | |
174 } | |
175 | |
98 } // namespace gpu | 176 } // namespace gpu |
OLD | NEW |