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

Side by Side Diff: gpu/command_buffer/service/sync_point_manager.cc

Issue 1542513002: Switch to standard integer types in gpu/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 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
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 "gpu/command_buffer/service/sync_point_manager.h" 5 #include "gpu/command_buffer/service/sync_point_manager.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <climits> 10 #include <climits>
8 11
9 #include "base/bind.h" 12 #include "base/bind.h"
10 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
11 #include "base/location.h" 14 #include "base/location.h"
12 #include "base/logging.h" 15 #include "base/logging.h"
13 #include "base/rand_util.h" 16 #include "base/rand_util.h"
14 #include "base/sequence_checker.h" 17 #include "base/sequence_checker.h"
15 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
16 19
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 base::AutoLock auto_lock(client_maps_lock_); 348 base::AutoLock auto_lock(client_maps_lock_);
346 ClientMap& client_map = client_maps_[namespace_id]; 349 ClientMap& client_map = client_maps_[namespace_id];
347 ClientMap::iterator it = client_map.find(client_id); 350 ClientMap::iterator it = client_map.find(client_id);
348 if (it != client_map.end()) { 351 if (it != client_map.end()) {
349 return it->second->client_state(); 352 return it->second->client_state();
350 } 353 }
351 } 354 }
352 return nullptr; 355 return nullptr;
353 } 356 }
354 357
355 uint32 SyncPointManager::GenerateSyncPoint() { 358 uint32_t SyncPointManager::GenerateSyncPoint() {
356 base::AutoLock lock(lock_); 359 base::AutoLock lock(lock_);
357 uint32 sync_point = next_sync_point_++; 360 uint32_t sync_point = next_sync_point_++;
358 // When an integer overflow occurs, don't return 0. 361 // When an integer overflow occurs, don't return 0.
359 if (!sync_point) 362 if (!sync_point)
360 sync_point = next_sync_point_++; 363 sync_point = next_sync_point_++;
361 364
362 // Note: wrapping would take days for a buggy/compromized renderer that would 365 // Note: wrapping would take days for a buggy/compromized renderer that would
363 // insert sync points in a loop, but if that were to happen, better explicitly 366 // insert sync points in a loop, but if that were to happen, better explicitly
364 // crash the GPU process than risk worse. 367 // crash the GPU process than risk worse.
365 // For normal operation (at most a few per frame), it would take ~a year to 368 // For normal operation (at most a few per frame), it would take ~a year to
366 // wrap. 369 // wrap.
367 CHECK(sync_point_map_.find(sync_point) == sync_point_map_.end()); 370 CHECK(sync_point_map_.find(sync_point) == sync_point_map_.end());
368 sync_point_map_.insert(std::make_pair(sync_point, ClosureList())); 371 sync_point_map_.insert(std::make_pair(sync_point, ClosureList()));
369 return sync_point; 372 return sync_point;
370 } 373 }
371 374
372 void SyncPointManager::RetireSyncPoint(uint32 sync_point) { 375 void SyncPointManager::RetireSyncPoint(uint32_t sync_point) {
373 ClosureList list; 376 ClosureList list;
374 { 377 {
375 base::AutoLock lock(lock_); 378 base::AutoLock lock(lock_);
376 SyncPointMap::iterator it = sync_point_map_.find(sync_point); 379 SyncPointMap::iterator it = sync_point_map_.find(sync_point);
377 if (it == sync_point_map_.end()) { 380 if (it == sync_point_map_.end()) {
378 LOG(ERROR) << "Attempted to retire sync point that" 381 LOG(ERROR) << "Attempted to retire sync point that"
379 " didn't exist or was already retired."; 382 " didn't exist or was already retired.";
380 return; 383 return;
381 } 384 }
382 list.swap(it->second); 385 list.swap(it->second);
383 sync_point_map_.erase(it); 386 sync_point_map_.erase(it);
384 if (allow_threaded_wait_) 387 if (allow_threaded_wait_)
385 retire_cond_var_.Broadcast(); 388 retire_cond_var_.Broadcast();
386 } 389 }
387 for (ClosureList::iterator i = list.begin(); i != list.end(); ++i) 390 for (ClosureList::iterator i = list.begin(); i != list.end(); ++i)
388 i->Run(); 391 i->Run();
389 } 392 }
390 393
391 void SyncPointManager::AddSyncPointCallback(uint32 sync_point, 394 void SyncPointManager::AddSyncPointCallback(uint32_t sync_point,
392 const base::Closure& callback) { 395 const base::Closure& callback) {
393 { 396 {
394 base::AutoLock lock(lock_); 397 base::AutoLock lock(lock_);
395 SyncPointMap::iterator it = sync_point_map_.find(sync_point); 398 SyncPointMap::iterator it = sync_point_map_.find(sync_point);
396 if (it != sync_point_map_.end()) { 399 if (it != sync_point_map_.end()) {
397 it->second.push_back(callback); 400 it->second.push_back(callback);
398 return; 401 return;
399 } 402 }
400 } 403 }
401 callback.Run(); 404 callback.Run();
402 } 405 }
403 406
404 bool SyncPointManager::IsSyncPointRetired(uint32 sync_point) { 407 bool SyncPointManager::IsSyncPointRetired(uint32_t sync_point) {
405 base::AutoLock lock(lock_); 408 base::AutoLock lock(lock_);
406 return IsSyncPointRetiredLocked(sync_point); 409 return IsSyncPointRetiredLocked(sync_point);
407 } 410 }
408 411
409 void SyncPointManager::WaitSyncPoint(uint32 sync_point) { 412 void SyncPointManager::WaitSyncPoint(uint32_t sync_point) {
410 if (!allow_threaded_wait_) { 413 if (!allow_threaded_wait_) {
411 DCHECK(IsSyncPointRetired(sync_point)); 414 DCHECK(IsSyncPointRetired(sync_point));
412 return; 415 return;
413 } 416 }
414 417
415 base::AutoLock lock(lock_); 418 base::AutoLock lock(lock_);
416 while (!IsSyncPointRetiredLocked(sync_point)) { 419 while (!IsSyncPointRetiredLocked(sync_point)) {
417 retire_cond_var_.Wait(); 420 retire_cond_var_.Wait();
418 } 421 }
419 } 422 }
420 423
421 bool SyncPointManager::IsSyncPointRetiredLocked(uint32 sync_point) { 424 bool SyncPointManager::IsSyncPointRetiredLocked(uint32_t sync_point) {
422 lock_.AssertAcquired(); 425 lock_.AssertAcquired();
423 return sync_point_map_.find(sync_point) == sync_point_map_.end(); 426 return sync_point_map_.find(sync_point) == sync_point_map_.end();
424 } 427 }
425 428
426 uint32_t SyncPointManager::GenerateOrderNumber() { 429 uint32_t SyncPointManager::GenerateOrderNumber() {
427 return global_order_num_.GetNext(); 430 return global_order_num_.GetNext();
428 } 431 }
429 432
430 void SyncPointManager::DestroySyncPointClient( 433 void SyncPointManager::DestroySyncPointClient(
431 CommandBufferNamespace namespace_id, uint64_t client_id) { 434 CommandBufferNamespace namespace_id, uint64_t client_id) {
432 DCHECK_GE(namespace_id, 0); 435 DCHECK_GE(namespace_id, 0);
433 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_maps_)); 436 DCHECK_LT(static_cast<size_t>(namespace_id), arraysize(client_maps_));
434 437
435 base::AutoLock auto_lock(client_maps_lock_); 438 base::AutoLock auto_lock(client_maps_lock_);
436 ClientMap& client_map = client_maps_[namespace_id]; 439 ClientMap& client_map = client_maps_[namespace_id];
437 ClientMap::iterator it = client_map.find(client_id); 440 ClientMap::iterator it = client_map.find(client_id);
438 DCHECK(it != client_map.end()); 441 DCHECK(it != client_map.end());
439 client_map.erase(it); 442 client_map.erase(it);
440 } 443 }
441 444
442 } // namespace gpu 445 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/sync_point_manager.h ('k') | gpu/command_buffer/service/sync_point_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698