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

Side by Side Diff: base/platform_thread_posix.cc

Issue 4812003: NaCl bringup of base.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 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 <dlfcn.h>
8 #include <errno.h> 7 #include <errno.h>
9 #include <sched.h> 8 #include <sched.h>
10 9
11 #if defined(OS_MACOSX) 10 #if defined(OS_MACOSX)
12 #include <mach/mach.h> 11 #include <mach/mach.h>
13 #include <sys/resource.h> 12 #include <sys/resource.h>
14 #include <algorithm> 13 #include <algorithm>
15 #endif 14 #endif
16 15
17 #if defined(OS_LINUX) 16 #if defined(OS_LINUX)
17 #include <dlfcn.h>
18 #include <sys/prctl.h> 18 #include <sys/prctl.h>
19 #include <sys/syscall.h> 19 #include <sys/syscall.h>
20 #include <unistd.h> 20 #include <unistd.h>
21 #endif 21 #endif
22 22
23 #if defined(OS_NACL)
24 #include <sys/nacl_syscalls.h>
25 #endif
26
23 #include "base/logging.h" 27 #include "base/logging.h"
24 #include "base/safe_strerror_posix.h" 28 #include "base/safe_strerror_posix.h"
25 29
26 #if defined(OS_MACOSX) 30 #if defined(OS_MACOSX)
27 namespace base { 31 namespace base {
28 void InitThreading(); 32 void InitThreading();
29 } // namespace base 33 } // namespace base
30 #endif 34 #endif
31 35
32 static void* ThreadFunc(void* closure) { 36 static void* ThreadFunc(void* closure) {
33 PlatformThread::Delegate* delegate = 37 PlatformThread::Delegate* delegate =
34 static_cast<PlatformThread::Delegate*>(closure); 38 static_cast<PlatformThread::Delegate*>(closure);
35 delegate->ThreadMain(); 39 delegate->ThreadMain();
36 return NULL; 40 return NULL;
37 } 41 }
38 42
39 // static 43 // static
40 PlatformThreadId PlatformThread::CurrentId() { 44 PlatformThreadId PlatformThread::CurrentId() {
41 // Pthreads doesn't have the concept of a thread ID, so we have to reach down 45 // Pthreads doesn't have the concept of a thread ID, so we have to reach down
42 // into the kernel. 46 // into the kernel.
43 #if defined(OS_MACOSX) 47 #if defined(OS_MACOSX)
44 return mach_thread_self(); 48 return mach_thread_self();
45 #elif defined(OS_LINUX) 49 #elif defined(OS_LINUX)
46 return syscall(__NR_gettid); 50 return syscall(__NR_gettid);
47 #elif defined(OS_FREEBSD) 51 #elif defined(OS_FREEBSD)
48 // TODO(BSD): find a better thread ID 52 // TODO(BSD): find a better thread ID
49 return reinterpret_cast<int64>(pthread_self()); 53 return reinterpret_cast<int64>(pthread_self());
54 #elif defined(OS_NACL)
55 return pthread_self();
50 #endif 56 #endif
51 } 57 }
52 58
53 // static 59 // static
54 void PlatformThread::YieldCurrentThread() { 60 void PlatformThread::YieldCurrentThread() {
55 sched_yield(); 61 sched_yield();
56 } 62 }
57 63
58 // static 64 // static
59 void PlatformThread::Sleep(int duration_ms) { 65 void PlatformThread::Sleep(int duration_ms) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 195
190 bool result = CreateThread(stack_size, false /* non-joinable thread */, 196 bool result = CreateThread(stack_size, false /* non-joinable thread */,
191 delegate, &unused); 197 delegate, &unused);
192 return result; 198 return result;
193 } 199 }
194 200
195 // static 201 // static
196 void PlatformThread::Join(PlatformThreadHandle thread_handle) { 202 void PlatformThread::Join(PlatformThreadHandle thread_handle) {
197 pthread_join(thread_handle, NULL); 203 pthread_join(thread_handle, NULL);
198 } 204 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698