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

Side by Side Diff: base/platform_thread_posix.cc

Issue 495002: Changes to base/ from a combination of FreeBSD and OpenBSD patches. (Closed)
Patch Set: minor tweaks Created 11 years 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/platform_thread.h" 5 #include "base/platform_thread.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sched.h> 8 #include <sched.h>
9 9
10 #if defined(OS_MACOSX) 10 #if defined(OS_MACOSX)
11 #include <mach/mach.h> 11 #include <mach/mach.h>
12 #elif defined(OS_LINUX) 12 #else
13 #include <sys/syscall.h> 13 #include <sys/syscall.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 #endif 15 #endif
16 16
17 #if defined(OS_MACOSX) 17 #if defined(OS_MACOSX)
18 namespace base { 18 namespace base {
19 void InitThreading(); 19 void InitThreading();
20 } // namespace 20 } // namespace
21 #endif 21 #endif
22 22
23 static void* ThreadFunc(void* closure) { 23 static void* ThreadFunc(void* closure) {
24 PlatformThread::Delegate* delegate = 24 PlatformThread::Delegate* delegate =
25 static_cast<PlatformThread::Delegate*>(closure); 25 static_cast<PlatformThread::Delegate*>(closure);
26 delegate->ThreadMain(); 26 delegate->ThreadMain();
27 return NULL; 27 return NULL;
28 } 28 }
29 29
30 // static 30 // static
31 PlatformThreadId PlatformThread::CurrentId() { 31 PlatformThreadId PlatformThread::CurrentId() {
32 // Pthreads doesn't have the concept of a thread ID, so we have to reach down 32 // Pthreads doesn't have the concept of a thread ID, so we have to reach down
33 // into the kernel. 33 // into the kernel.
34 #if defined(OS_MACOSX) 34 #if defined(OS_MACOSX)
35 return mach_thread_self(); 35 return mach_thread_self();
36 #elif defined(OS_LINUX) 36 #elif defined(OS_LINUX)
37 return syscall(__NR_gettid); 37 return syscall(__NR_gettid);
38 #elif defined(OS_FREEBSD)
39 // TODO(BSD): find a better thread ID
40 return reinterpret_cast<int64>(pthread_self());
38 #endif 41 #endif
39 } 42 }
40 43
41 // static 44 // static
42 void PlatformThread::YieldCurrentThread() { 45 void PlatformThread::YieldCurrentThread() {
43 sched_yield(); 46 sched_yield();
44 } 47 }
45 48
46 // static 49 // static
47 void PlatformThread::Sleep(int duration_ms) { 50 void PlatformThread::Sleep(int duration_ms) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 114
112 bool result = CreateThread(stack_size, false /* non-joinable thread */, 115 bool result = CreateThread(stack_size, false /* non-joinable thread */,
113 delegate, &unused); 116 delegate, &unused);
114 return result; 117 return result;
115 } 118 }
116 119
117 // static 120 // static
118 void PlatformThread::Join(PlatformThreadHandle thread_handle) { 121 void PlatformThread::Join(PlatformThreadHandle thread_handle) {
119 pthread_join(thread_handle, NULL); 122 pthread_join(thread_handle, NULL);
120 } 123 }
OLDNEW
« base/message_loop.h ('K') | « base/native_library.h ('k') | base/process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698