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

Side by Side Diff: base/threading/platform_thread_posix.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 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
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 "base/threading/platform_thread.h" 5 #include "base/threading/platform_thread.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <sched.h> 9 #include <sched.h>
10 #include <stddef.h> 10 #include <stddef.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 #include <sys/resource.h> 12 #include <sys/resource.h>
13 #include <sys/time.h> 13 #include <sys/time.h>
14 14
15 #include <memory>
16
15 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
16 #include "base/logging.h" 18 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/threading/platform_thread_internal_posix.h" 19 #include "base/threading/platform_thread_internal_posix.h"
19 #include "base/threading/thread_id_name_manager.h" 20 #include "base/threading/thread_id_name_manager.h"
20 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 23
23 #if defined(OS_LINUX) 24 #if defined(OS_LINUX)
24 #include <sys/syscall.h> 25 #include <sys/syscall.h>
25 #elif defined(OS_ANDROID) 26 #elif defined(OS_ANDROID)
26 #include <sys/types.h> 27 #include <sys/types.h>
27 #endif 28 #endif
(...skipping 12 matching lines...) Expand all
40 41
41 PlatformThread::Delegate* delegate; 42 PlatformThread::Delegate* delegate;
42 bool joinable; 43 bool joinable;
43 ThreadPriority priority; 44 ThreadPriority priority;
44 }; 45 };
45 46
46 void* ThreadFunc(void* params) { 47 void* ThreadFunc(void* params) {
47 PlatformThread::Delegate* delegate = nullptr; 48 PlatformThread::Delegate* delegate = nullptr;
48 49
49 { 50 {
50 scoped_ptr<ThreadParams> thread_params(static_cast<ThreadParams*>(params)); 51 std::unique_ptr<ThreadParams> thread_params(
52 static_cast<ThreadParams*>(params));
51 53
52 delegate = thread_params->delegate; 54 delegate = thread_params->delegate;
53 if (!thread_params->joinable) 55 if (!thread_params->joinable)
54 base::ThreadRestrictions::SetSingletonAllowed(false); 56 base::ThreadRestrictions::SetSingletonAllowed(false);
55 57
56 #if !defined(OS_NACL) 58 #if !defined(OS_NACL)
57 // Threads on linux/android may inherit their priority from the thread 59 // Threads on linux/android may inherit their priority from the thread
58 // where they were created. This explicitly sets the priority of all new 60 // where they were created. This explicitly sets the priority of all new
59 // threads. 61 // threads.
60 PlatformThread::SetCurrentThreadPriority(thread_params->priority); 62 PlatformThread::SetCurrentThreadPriority(thread_params->priority);
(...skipping 30 matching lines...) Expand all
91 if (!joinable) 93 if (!joinable)
92 pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED); 94 pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
93 95
94 // Get a better default if available. 96 // Get a better default if available.
95 if (stack_size == 0) 97 if (stack_size == 0)
96 stack_size = base::GetDefaultThreadStackSize(attributes); 98 stack_size = base::GetDefaultThreadStackSize(attributes);
97 99
98 if (stack_size > 0) 100 if (stack_size > 0)
99 pthread_attr_setstacksize(&attributes, stack_size); 101 pthread_attr_setstacksize(&attributes, stack_size);
100 102
101 scoped_ptr<ThreadParams> params(new ThreadParams); 103 std::unique_ptr<ThreadParams> params(new ThreadParams);
102 params->delegate = delegate; 104 params->delegate = delegate;
103 params->joinable = joinable; 105 params->joinable = joinable;
104 params->priority = priority; 106 params->priority = priority;
105 107
106 pthread_t handle; 108 pthread_t handle;
107 int err = pthread_create(&handle, &attributes, ThreadFunc, params.get()); 109 int err = pthread_create(&handle, &attributes, ThreadFunc, params.get());
108 bool success = !err; 110 bool success = !err;
109 if (success) { 111 if (success) {
110 // ThreadParams should be deleted on the created thread after used. 112 // ThreadParams should be deleted on the created thread after used.
111 ignore_result(params.release()); 113 ignore_result(params.release());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return ThreadPriority::NORMAL; 257 return ThreadPriority::NORMAL;
256 } 258 }
257 259
258 return internal::NiceValueToThreadPriority(nice_value); 260 return internal::NiceValueToThreadPriority(nice_value);
259 #endif // !defined(OS_NACL) 261 #endif // !defined(OS_NACL)
260 } 262 }
261 263
262 #endif // !defined(OS_MACOSX) 264 #endif // !defined(OS_MACOSX)
263 265
264 } // namespace base 266 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/non_thread_safe_unittest.cc ('k') | base/threading/sequenced_task_runner_handle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698