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

Side by Side Diff: tools/cygprofile/cygprofile.cc

Issue 1869503004: Convert //tools to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, change iwyu fixes for converted directories to include <memory> Created 4 years, 8 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 | « tools/cygprofile/cygprofile.h ('k') | tools/cygprofile/cygprofile_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "tools/cygprofile/cygprofile.h" 5 #include "tools/cygprofile/cygprofile.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 #include <sys/stat.h> 11 #include <sys/stat.h>
12 #include <sys/syscall.h> 12 #include <sys/syscall.h>
13 #include <sys/time.h> 13 #include <sys/time.h>
14 #include <sys/types.h> 14 #include <sys/types.h>
15 15
16 #include <cstdio> 16 #include <cstdio>
17 #include <fstream> 17 #include <fstream>
18 #include <string> 18 #include <string>
19 #include <vector> 19 #include <vector>
20 20
21 #include "base/bind.h" 21 #include "base/bind.h"
22 #include "base/containers/hash_tables.h" 22 #include "base/containers/hash_tables.h"
23 #include "base/files/scoped_file.h" 23 #include "base/files/scoped_file.h"
24 #include "base/lazy_instance.h" 24 #include "base/lazy_instance.h"
25 #include "base/logging.h" 25 #include "base/logging.h"
26 #include "base/macros.h" 26 #include "base/macros.h"
27 #include "base/memory/ptr_util.h"
27 #include "base/stl_util.h" 28 #include "base/stl_util.h"
28 #include "base/strings/string_number_conversions.h" 29 #include "base/strings/string_number_conversions.h"
29 #include "base/strings/string_piece.h" 30 #include "base/strings/string_piece.h"
30 #include "base/strings/stringprintf.h" 31 #include "base/strings/stringprintf.h"
31 #include "base/synchronization/lock.h" 32 #include "base/synchronization/lock.h"
32 33
33 namespace cygprofile { 34 namespace cygprofile {
34 namespace { 35 namespace {
35 36
36 // Allow 8 MBytes of data for each thread log. 37 // Allow 8 MBytes of data for each thread log.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 ThreadLogsManager::ThreadLogsManager(const base::Closure& wait_callback, 260 ThreadLogsManager::ThreadLogsManager(const base::Closure& wait_callback,
260 const base::Closure& notify_callback) 261 const base::Closure& notify_callback)
261 262
262 : wait_callback_(wait_callback), 263 : wait_callback_(wait_callback),
263 notify_callback_(notify_callback) { 264 notify_callback_(notify_callback) {
264 } 265 }
265 266
266 ThreadLogsManager::~ThreadLogsManager() { 267 ThreadLogsManager::~ThreadLogsManager() {
267 // Note that the internal thread does some work until it sees |flush_thread_| 268 // Note that the internal thread does some work until it sees |flush_thread_|
268 // = NULL. 269 // = NULL.
269 scoped_ptr<Thread> flush_thread; 270 std::unique_ptr<Thread> flush_thread;
270 { 271 {
271 base::AutoLock auto_lock(lock_); 272 base::AutoLock auto_lock(lock_);
272 flush_thread_.swap(flush_thread); 273 flush_thread_.swap(flush_thread);
273 } 274 }
274 flush_thread.reset(); // Joins the flush thread. 275 flush_thread.reset(); // Joins the flush thread.
275 276
276 STLDeleteContainerPointers(logs_.begin(), logs_.end()); 277 STLDeleteContainerPointers(logs_.begin(), logs_.end());
277 } 278 }
278 279
279 void ThreadLogsManager::AddLog(scoped_ptr<ThreadLog> new_log) { 280 void ThreadLogsManager::AddLog(std::unique_ptr<ThreadLog> new_log) {
280 base::AutoLock auto_lock(lock_); 281 base::AutoLock auto_lock(lock_);
281 282
282 if (logs_.empty()) 283 if (logs_.empty())
283 StartInternalFlushThread_Locked(); 284 StartInternalFlushThread_Locked();
284 285
285 logs_.push_back(new_log.release()); 286 logs_.push_back(new_log.release());
286 } 287 }
287 288
288 void ThreadLogsManager::StartInternalFlushThread_Locked() { 289 void ThreadLogsManager::StartInternalFlushThread_Locked() {
289 lock_.AssertAcquired(); 290 lock_.AssertAcquired();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 void __cyg_profile_func_enter(void* this_fn, void* call_site) 355 void __cyg_profile_func_enter(void* this_fn, void* call_site)
355 __attribute__((no_instrument_function)); 356 __attribute__((no_instrument_function));
356 void __cyg_profile_func_exit(void* this_fn, void* call_site) 357 void __cyg_profile_func_exit(void* this_fn, void* call_site)
357 __attribute__((no_instrument_function)); 358 __attribute__((no_instrument_function));
358 359
359 void __cyg_profile_func_enter(void* this_fn, void* callee_unused) { 360 void __cyg_profile_func_enter(void* this_fn, void* callee_unused) {
360 if (g_tls_log == NULL) { 361 if (g_tls_log == NULL) {
361 g_tls_log = kMagicBeingConstructed; 362 g_tls_log = kMagicBeingConstructed;
362 ThreadLog* new_log = new ThreadLog(); 363 ThreadLog* new_log = new ThreadLog();
363 CHECK(new_log); 364 CHECK(new_log);
364 g_logs_manager.Pointer()->AddLog(make_scoped_ptr(new_log)); 365 g_logs_manager.Pointer()->AddLog(base::WrapUnique(new_log));
365 g_tls_log = new_log; 366 g_tls_log = new_log;
366 } 367 }
367 368
368 if (g_tls_log != kMagicBeingConstructed) 369 if (g_tls_log != kMagicBeingConstructed)
369 g_tls_log->AddEntry(this_fn); 370 g_tls_log->AddEntry(this_fn);
370 } 371 }
371 372
372 void __cyg_profile_func_exit(void* this_fn, void* call_site) {} 373 void __cyg_profile_func_exit(void* this_fn, void* call_site) {}
373 374
374 } // extern "C" 375 } // extern "C"
375 } // namespace cygprofile 376 } // namespace cygprofile
OLDNEW
« no previous file with comments | « tools/cygprofile/cygprofile.h ('k') | tools/cygprofile/cygprofile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698