Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Side by Side Diff: content/common/gpu/sync_point_manager.cc

Issue 288153004: SyncPointManager never returns 0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to ToT Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/gpu/sync_point_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/common/gpu/sync_point_manager.h" 5 #include "content/common/gpu/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 11
12 namespace content { 12 namespace content {
13 13
14 static const int kMaxSyncBase = INT_MAX; 14 static const int kMaxSyncBase = INT_MAX;
15 15
16 SyncPointManager::SyncPointManager() 16 SyncPointManager::SyncPointManager()
17 : next_sync_point_(base::RandInt(1, kMaxSyncBase)) { 17 : next_sync_point_(base::RandInt(1, kMaxSyncBase)) {
18 // To reduce the risk that a sync point created in a previous GPU process 18 // To reduce the risk that a sync point created in a previous GPU process
19 // will be in flight in the next GPU process, randomize the starting sync 19 // will be in flight in the next GPU process, randomize the starting sync
20 // point number. http://crbug.com/373452 20 // point number. http://crbug.com/373452
21 } 21 }
22 22
23 SyncPointManager::~SyncPointManager() { 23 SyncPointManager::~SyncPointManager() {
24 } 24 }
25 25
26 uint32 SyncPointManager::GenerateSyncPoint() { 26 uint32 SyncPointManager::GenerateSyncPoint() {
27 base::AutoLock lock(lock_); 27 base::AutoLock lock(lock_);
28 uint32 sync_point = next_sync_point_++; 28 uint32 sync_point = next_sync_point_++;
29 // When an integer overflow occurs, don't return 0.
30 if (!sync_point)
31 sync_point = next_sync_point_++;
29 32
30 // Note: wrapping would take days for a buggy/compromized renderer that would 33 // Note: wrapping would take days for a buggy/compromized renderer that would
31 // insert sync points in a loop, but if that were to happen, better explicitly 34 // insert sync points in a loop, but if that were to happen, better explicitly
32 // crash the GPU process than risk worse. 35 // crash the GPU process than risk worse.
33 // For normal operation (at most a few per frame), it would take ~a year to 36 // For normal operation (at most a few per frame), it would take ~a year to
34 // wrap. 37 // wrap.
35 CHECK(sync_point_map_.find(sync_point) == sync_point_map_.end()); 38 CHECK(sync_point_map_.find(sync_point) == sync_point_map_.end());
36 sync_point_map_.insert(std::make_pair(sync_point, ClosureList())); 39 sync_point_map_.insert(std::make_pair(sync_point, ClosureList()));
37 return sync_point; 40 return sync_point;
38 } 41 }
(...skipping 29 matching lines...) Expand all
68 bool SyncPointManager::IsSyncPointRetired(uint32 sync_point) { 71 bool SyncPointManager::IsSyncPointRetired(uint32 sync_point) {
69 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK(thread_checker_.CalledOnValidThread());
70 { 73 {
71 base::AutoLock lock(lock_); 74 base::AutoLock lock(lock_);
72 SyncPointMap::iterator it = sync_point_map_.find(sync_point); 75 SyncPointMap::iterator it = sync_point_map_.find(sync_point);
73 return it == sync_point_map_.end(); 76 return it == sync_point_map_.end();
74 } 77 }
75 } 78 }
76 79
77 } // namespace content 80 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/sync_point_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698