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

Side by Side Diff: src/platform-posix.cc

Issue 20734002: Implement correct OS and CC detection. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reverted changes to atomicops*.h Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/platform-posix.h ('k') | src/platform-win32.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Platform specific code for POSIX goes here. This is not a platform on its 28 // Platform specific code for POSIX goes here. This is not a platform on its
29 // own but contains the parts which are the same across POSIX platforms Linux, 29 // own but contains the parts which are the same across POSIX platforms Linux,
30 // Mac OS, FreeBSD and OpenBSD. 30 // Mac OS, FreeBSD and OpenBSD.
31 31
32 #include "platform-posix.h" 32 #include "platform-posix.h"
33 33
34 #include <dlfcn.h> 34 #include <dlfcn.h>
35 #include <pthread.h> 35 #include <pthread.h>
36 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) 36 #if V8_OS_FREEBSD || V8_OS_OPENBSD
37 #include <pthread_np.h> // for pthread_set_name_np 37 #include <pthread_np.h> // for pthread_set_name_np
38 #endif 38 #endif
39 #include <sched.h> // for sched_yield 39 #include <sched.h> // for sched_yield
40 #include <unistd.h> 40 #include <unistd.h>
41 #include <errno.h> 41 #include <errno.h>
42 #include <time.h> 42 #include <time.h>
43 43
44 #include <sys/mman.h> 44 #include <sys/mman.h>
45 #include <sys/socket.h> 45 #include <sys/socket.h>
46 #include <sys/resource.h> 46 #include <sys/resource.h>
47 #include <sys/time.h> 47 #include <sys/time.h>
48 #include <sys/types.h> 48 #include <sys/types.h>
49 #include <sys/stat.h> 49 #include <sys/stat.h>
50 #if defined(__linux__) 50 #if V8_OS_LINUX
51 #include <sys/prctl.h> // for prctl 51 #include <sys/prctl.h> // for prctl
52 #endif 52 #elif V8_OS_BSD4
53 #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \
54 defined(__NetBSD__) || defined(__OpenBSD__)
55 #include <sys/sysctl.h> // for sysctl 53 #include <sys/sysctl.h> // for sysctl
56 #endif 54 #endif
57 55
58 #include <arpa/inet.h> 56 #include <arpa/inet.h>
59 #include <netinet/in.h> 57 #include <netinet/in.h>
60 #include <netdb.h> 58 #include <netdb.h>
61 59
62 #undef MAP_TYPE 60 #undef MAP_TYPE
63 61
64 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) 62 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
65 #define LOG_TAG "v8" 63 #define LOG_TAG "v8"
66 #include <android/log.h> 64 #include <android/log.h>
67 #endif 65 #endif
68 66
69 #include "v8.h" 67 #include "v8.h"
70 68
71 #include "codegen.h" 69 #include "codegen.h"
72 #include "platform.h" 70 #include "platform.h"
73 71
74 namespace v8 { 72 namespace v8 {
75 namespace internal { 73 namespace internal {
76 74
77 // 0 is never a valid thread id. 75 // 0 is never a valid thread id.
78 static const pthread_t kNoThread = (pthread_t) 0; 76 static const pthread_t kNoThread = (pthread_t) 0;
79 77
80 78
81 uint64_t OS::CpuFeaturesImpliedByPlatform() { 79 uint64_t OS::CpuFeaturesImpliedByPlatform() {
82 #if defined(__APPLE__) 80 #if V8_OS_DARWIN
83 // Mac OS X requires all these to install so we can assume they are present. 81 // Mac OS X requires all these to install so we can assume they are present.
84 // These constants are defined by the CPUid instructions. 82 // These constants are defined by the CPUid instructions.
85 const uint64_t one = 1; 83 const uint64_t one = 1;
86 return (one << SSE2) | (one << CMOV) | (one << RDTSC) | (one << CPUID); 84 return (one << SSE2) | (one << CMOV) | (one << RDTSC) | (one << CPUID);
87 #else 85 #else
88 return 0; // Nothing special about the other systems. 86 return 0; // Nothing special about the other systems.
89 #endif 87 #endif
90 } 88 }
91 89
92 90
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void OS::Free(void* address, const size_t size) { 126 void OS::Free(void* address, const size_t size) {
129 // TODO(1240712): munmap has a return value which is ignored here. 127 // TODO(1240712): munmap has a return value which is ignored here.
130 int result = munmap(address, size); 128 int result = munmap(address, size);
131 USE(result); 129 USE(result);
132 ASSERT(result == 0); 130 ASSERT(result == 0);
133 } 131 }
134 132
135 133
136 // Get rid of writable permission on code allocations. 134 // Get rid of writable permission on code allocations.
137 void OS::ProtectCode(void* address, const size_t size) { 135 void OS::ProtectCode(void* address, const size_t size) {
138 #if defined(__CYGWIN__) 136 #if V8_OS_CYGWIN
139 DWORD old_protect; 137 DWORD old_protect;
140 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); 138 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
141 #elif defined(__native_client__) 139 #elif V8_OS_NACL
142 // The Native Client port of V8 uses an interpreter, so 140 // The Native Client port of V8 uses an interpreter, so
143 // code pages don't need PROT_EXEC. 141 // code pages don't need PROT_EXEC.
144 mprotect(address, size, PROT_READ); 142 mprotect(address, size, PROT_READ);
145 #else 143 #else
146 mprotect(address, size, PROT_READ | PROT_EXEC); 144 mprotect(address, size, PROT_READ | PROT_EXEC);
147 #endif 145 #endif
148 } 146 }
149 147
150 148
151 // Create guard pages. 149 // Create guard pages.
152 void OS::Guard(void* address, const size_t size) { 150 void OS::Guard(void* address, const size_t size) {
153 #if defined(__CYGWIN__) 151 #if V8_OS_CYGWIN
154 DWORD oldprotect; 152 DWORD oldprotect;
155 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect); 153 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);
156 #else 154 #else
157 mprotect(address, size, PROT_NONE); 155 mprotect(address, size, PROT_NONE);
158 #endif 156 #endif
159 } 157 }
160 158
161 159
162 void* OS::GetRandomMmapAddr() { 160 void* OS::GetRandomMmapAddr() {
163 #if defined(__native_client__) 161 #if V8_OS_NACL
164 // TODO(bradchen): restore randomization once Native Client gets 162 // TODO(bradchen): restore randomization once Native Client gets
165 // smarter about using mmap address hints. 163 // smarter about using mmap address hints.
166 // See http://code.google.com/p/nativeclient/issues/3341 164 // See http://code.google.com/p/nativeclient/issues/3341
167 return NULL; 165 return NULL;
168 #endif 166 #endif
169 Isolate* isolate = Isolate::UncheckedCurrent(); 167 Isolate* isolate = Isolate::UncheckedCurrent();
170 // Note that the current isolate isn't set up in a call path via 168 // Note that the current isolate isn't set up in a call path via
171 // CpuFeatures::Probe. We don't care about randomization in this case because 169 // CpuFeatures::Probe. We don't care about randomization in this case because
172 // the code page is immediately freed. 170 // the code page is immediately freed.
173 if (isolate != NULL) { 171 if (isolate != NULL) {
174 #if V8_TARGET_ARCH_X64 172 #if V8_HOST_ARCH_64_BIT
175 uint64_t rnd1 = V8::RandomPrivate(isolate); 173 uint64_t rnd1 = V8::RandomPrivate(isolate);
176 uint64_t rnd2 = V8::RandomPrivate(isolate); 174 uint64_t rnd2 = V8::RandomPrivate(isolate);
177 uint64_t raw_addr = (rnd1 << 32) ^ rnd2; 175 uint64_t raw_addr = (rnd1 << 32) ^ rnd2;
178 // Currently available CPUs have 48 bits of virtual addressing. Truncate 176 // Currently available CPUs have 48 bits of virtual addressing. Truncate
179 // the hint address to 46 bits to give the kernel a fighting chance of 177 // the hint address to 46 bits to give the kernel a fighting chance of
180 // fulfilling our placement request. 178 // fulfilling our placement request.
181 raw_addr &= V8_UINT64_C(0x3ffffffff000); 179 raw_addr &= V8_UINT64_C(0x3ffffffff000);
182 #else 180 #else
183 uint32_t raw_addr = V8::RandomPrivate(isolate); 181 uint32_t raw_addr = V8::RandomPrivate(isolate);
184 182
185 raw_addr &= 0x3ffff000; 183 raw_addr &= 0x3ffff000;
186 184
187 # ifdef __sun 185 #if V8_OS_SOLARIS
188 // For our Solaris/illumos mmap hint, we pick a random address in the bottom 186 // For our Solaris/illumos mmap hint, we pick a random address in the bottom
189 // half of the top half of the address space (that is, the third quarter). 187 // half of the top half of the address space (that is, the third quarter).
190 // Because we do not MAP_FIXED, this will be treated only as a hint -- the 188 // Because we do not MAP_FIXED, this will be treated only as a hint -- the
191 // system will not fail to mmap() because something else happens to already 189 // system will not fail to mmap() because something else happens to already
192 // be mapped at our random address. We deliberately set the hint high enough 190 // be mapped at our random address. We deliberately set the hint high enough
193 // to get well above the system's break (that is, the heap); Solaris and 191 // to get well above the system's break (that is, the heap); Solaris and
194 // illumos will try the hint and if that fails allocate as if there were 192 // illumos will try the hint and if that fails allocate as if there were
195 // no hint at all. The high hint prevents the break from getting hemmed in 193 // no hint at all. The high hint prevents the break from getting hemmed in
196 // at low values, ceding half of the address space to the system heap. 194 // at low values, ceding half of the address space to the system heap.
197 raw_addr += 0x80000000; 195 raw_addr += 0x80000000;
198 # else 196 #else
199 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a 197 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a
200 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos 198 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos
201 // 10.6 and 10.7. 199 // 10.6 and 10.7.
202 raw_addr += 0x20000000; 200 raw_addr += 0x20000000;
203 # endif 201 #endif // V8_OS_SOLARIS
204 #endif 202 #endif // V8_HOST_ARCH_64_BIT
205 return reinterpret_cast<void*>(raw_addr); 203 return reinterpret_cast<void*>(raw_addr);
206 } 204 }
207 return NULL; 205 return NULL;
208 } 206 }
209 207
210 208
211 size_t OS::AllocateAlignment() { 209 size_t OS::AllocateAlignment() {
212 return getpagesize(); 210 return getpagesize();
213 } 211 }
214 212
(...skipping 17 matching lines...) Expand all
232 abort(); 230 abort();
233 } 231 }
234 232
235 233
236 void OS::DebugBreak() { 234 void OS::DebugBreak() {
237 #if V8_HOST_ARCH_ARM 235 #if V8_HOST_ARCH_ARM
238 asm("bkpt 0"); 236 asm("bkpt 0");
239 #elif V8_HOST_ARCH_MIPS 237 #elif V8_HOST_ARCH_MIPS
240 asm("break"); 238 asm("break");
241 #elif V8_HOST_ARCH_IA32 239 #elif V8_HOST_ARCH_IA32
242 #if defined(__native_client__) 240 #if V8_OS_NACL
243 asm("hlt"); 241 asm("hlt");
244 #else 242 #else
245 asm("int $3"); 243 asm("int $3");
246 #endif // __native_client__ 244 #endif // V8_OS_NACL
247 #elif V8_HOST_ARCH_X64 245 #elif V8_HOST_ARCH_X64
248 asm("int $3"); 246 asm("int $3");
249 #else 247 #else
250 #error Unsupported host architecture. 248 #error Unsupported host architecture.
251 #endif 249 #endif
252 } 250 }
253 251
254 252
255 // ---------------------------------------------------------------------------- 253 // ----------------------------------------------------------------------------
256 // Math functions 254 // Math functions
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 377
380 void OS::Print(const char* format, ...) { 378 void OS::Print(const char* format, ...) {
381 va_list args; 379 va_list args;
382 va_start(args, format); 380 va_start(args, format);
383 VPrint(format, args); 381 VPrint(format, args);
384 va_end(args); 382 va_end(args);
385 } 383 }
386 384
387 385
388 void OS::VPrint(const char* format, va_list args) { 386 void OS::VPrint(const char* format, va_list args) {
389 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) 387 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
390 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); 388 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
391 #else 389 #else
392 vprintf(format, args); 390 vprintf(format, args);
393 #endif 391 #endif
394 } 392 }
395 393
396 394
397 void OS::FPrint(FILE* out, const char* format, ...) { 395 void OS::FPrint(FILE* out, const char* format, ...) {
398 va_list args; 396 va_list args;
399 va_start(args, format); 397 va_start(args, format);
400 VFPrint(out, format, args); 398 VFPrint(out, format, args);
401 va_end(args); 399 va_end(args);
402 } 400 }
403 401
404 402
405 void OS::VFPrint(FILE* out, const char* format, va_list args) { 403 void OS::VFPrint(FILE* out, const char* format, va_list args) {
406 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) 404 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
407 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); 405 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
408 #else 406 #else
409 vfprintf(out, format, args); 407 vfprintf(out, format, args);
410 #endif 408 #endif
411 } 409 }
412 410
413 411
414 void OS::PrintError(const char* format, ...) { 412 void OS::PrintError(const char* format, ...) {
415 va_list args; 413 va_list args;
416 va_start(args, format); 414 va_start(args, format);
417 VPrintError(format, args); 415 VPrintError(format, args);
418 va_end(args); 416 va_end(args);
419 } 417 }
420 418
421 419
422 void OS::VPrintError(const char* format, va_list args) { 420 void OS::VPrintError(const char* format, va_list args) {
423 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) 421 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
424 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args); 422 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args);
425 #else 423 #else
426 vfprintf(stderr, format, args); 424 vfprintf(stderr, format, args);
427 #endif 425 #endif
428 } 426 }
429 427
430 428
431 int OS::SNPrintF(Vector<char> str, const char* format, ...) { 429 int OS::SNPrintF(Vector<char> str, const char* format, ...) {
432 va_list args; 430 va_list args;
433 va_start(args, format); 431 va_start(args, format);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 OS::MemMoveFunction CreateMemMoveFunction(); 463 OS::MemMoveFunction CreateMemMoveFunction();
466 464
467 // Copy memory area. No restrictions. 465 // Copy memory area. No restrictions.
468 void OS::MemMove(void* dest, const void* src, size_t size) { 466 void OS::MemMove(void* dest, const void* src, size_t size) {
469 if (size == 0) return; 467 if (size == 0) return;
470 // Note: here we rely on dependent reads being ordered. This is true 468 // Note: here we rely on dependent reads being ordered. This is true
471 // on all architectures we currently support. 469 // on all architectures we currently support.
472 (*memmove_function)(dest, src, size); 470 (*memmove_function)(dest, src, size);
473 } 471 }
474 472
475 #elif defined(V8_HOST_ARCH_ARM) 473 #elif V8_HOST_ARCH_ARM
476 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest, 474 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest,
477 const uint8_t* src, 475 const uint8_t* src,
478 size_t chars) { 476 size_t chars) {
479 uint16_t *limit = dest + chars; 477 uint16_t *limit = dest + chars;
480 while (dest < limit) { 478 while (dest < limit) {
481 *dest++ = static_cast<uint16_t>(*src++); 479 *dest++ = static_cast<uint16_t>(*src++);
482 } 480 }
483 } 481 }
484 482
485 483
486 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper; 484 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper;
487 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = 485 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function =
488 &OS::MemCopyUint16Uint8Wrapper; 486 &OS::MemCopyUint16Uint8Wrapper;
489 // Defined in codegen-arm.cc. 487 // Defined in codegen-arm.cc.
490 OS::MemCopyUint8Function CreateMemCopyUint8Function( 488 OS::MemCopyUint8Function CreateMemCopyUint8Function(
491 OS::MemCopyUint8Function stub); 489 OS::MemCopyUint8Function stub);
492 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function( 490 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function(
493 OS::MemCopyUint16Uint8Function stub); 491 OS::MemCopyUint16Uint8Function stub);
494 #endif 492 #endif
495 493
496 494
497 void OS::PostSetUp() { 495 void OS::PostSetUp() {
498 #if V8_TARGET_ARCH_IA32 496 #if V8_TARGET_ARCH_IA32
499 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); 497 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction();
500 if (generated_memmove != NULL) { 498 if (generated_memmove != NULL) {
501 memmove_function = generated_memmove; 499 memmove_function = generated_memmove;
502 } 500 }
503 #elif defined(V8_HOST_ARCH_ARM) 501 #elif V8_HOST_ARCH_ARM
504 OS::memcopy_uint8_function = 502 OS::memcopy_uint8_function =
505 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper); 503 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper);
506 OS::memcopy_uint16_uint8_function = 504 OS::memcopy_uint16_uint8_function =
507 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper); 505 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper);
508 #endif 506 #endif
509 init_fast_sin_function(); 507 init_fast_sin_function();
510 init_fast_cos_function(); 508 init_fast_cos_function();
511 init_fast_tan_function(); 509 init_fast_tan_function();
512 init_fast_log_function(); 510 init_fast_log_function();
513 // fast_exp is initialized lazily. 511 // fast_exp is initialized lazily.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 set_name(options.name()); 544 set_name(options.name());
547 } 545 }
548 546
549 547
550 Thread::~Thread() { 548 Thread::~Thread() {
551 delete data_; 549 delete data_;
552 } 550 }
553 551
554 552
555 static void SetThreadName(const char* name) { 553 static void SetThreadName(const char* name) {
556 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) 554 #if V8_OS_FREEBSD || V8_OS_OPENBSD
557 pthread_set_name_np(pthread_self(), name); 555 pthread_set_name_np(pthread_self(), name);
558 #elif defined(__NetBSD__) 556 #elif V8_OS_NETBSD
559 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP); 557 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP);
560 pthread_setname_np(pthread_self(), "%s", name); 558 pthread_setname_np(pthread_self(), "%s", name);
561 #elif defined(__APPLE__) 559 #elif V8_OS_DARWIN
562 // pthread_setname_np is only available in 10.6 or later, so test 560 // pthread_setname_np is only available in 10.6 or later, so test
563 // for it at runtime. 561 // for it at runtime.
564 int (*dynamic_pthread_setname_np)(const char*); 562 int (*dynamic_pthread_setname_np)(const char*);
565 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = 563 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) =
566 dlsym(RTLD_DEFAULT, "pthread_setname_np"); 564 dlsym(RTLD_DEFAULT, "pthread_setname_np");
567 if (dynamic_pthread_setname_np == NULL) 565 if (dynamic_pthread_setname_np == NULL)
568 return; 566 return;
569 567
570 // Mac OS X does not expose the length limit of the name, so hardcode it. 568 // Mac OS X does not expose the length limit of the name, so hardcode it.
571 static const int kMaxNameLength = 63; 569 static const int kMaxNameLength = 63;
(...skipping 26 matching lines...) Expand all
598 } 596 }
599 597
600 598
601 void Thread::Start() { 599 void Thread::Start() {
602 int result; 600 int result;
603 pthread_attr_t attr; 601 pthread_attr_t attr;
604 memset(&attr, 0, sizeof(attr)); 602 memset(&attr, 0, sizeof(attr));
605 result = pthread_attr_init(&attr); 603 result = pthread_attr_init(&attr);
606 ASSERT_EQ(0, result); 604 ASSERT_EQ(0, result);
607 // Native client uses default stack size. 605 // Native client uses default stack size.
608 #if !defined(__native_client__) 606 #if !V8_OS_NACL
609 if (stack_size_ > 0) { 607 if (stack_size_ > 0) {
610 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); 608 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
611 ASSERT_EQ(0, result); 609 ASSERT_EQ(0, result);
612 } 610 }
613 #endif 611 #endif
614 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); 612 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this);
615 ASSERT_EQ(0, result); 613 ASSERT_EQ(0, result);
616 result = pthread_attr_destroy(&attr); 614 result = pthread_attr_destroy(&attr);
617 ASSERT_EQ(0, result); 615 ASSERT_EQ(0, result);
618 ASSERT(data_->thread_ != kNoThread); 616 ASSERT(data_->thread_ != kNoThread);
619 USE(result); 617 USE(result);
620 } 618 }
621 619
622 620
623 void Thread::Join() { 621 void Thread::Join() {
624 pthread_join(data_->thread_, NULL); 622 pthread_join(data_->thread_, NULL);
625 } 623 }
626 624
627 625
628 void Thread::YieldCPU() { 626 void Thread::YieldCPU() {
629 int result = sched_yield(); 627 int result = sched_yield();
630 ASSERT_EQ(0, result); 628 ASSERT_EQ(0, result);
631 USE(result); 629 USE(result);
632 } 630 }
633 631
634 632
635 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) { 633 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) {
636 #if defined(__CYGWIN__) 634 #if V8_OS_CYGWIN
637 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps 635 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps
638 // because pthread_key_t is a pointer type on Cygwin. This will probably not 636 // because pthread_key_t is a pointer type on Cygwin. This will probably not
639 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway. 637 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway.
640 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); 638 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
641 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key); 639 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key);
642 return static_cast<Thread::LocalStorageKey>(ptr_key); 640 return static_cast<Thread::LocalStorageKey>(ptr_key);
643 #else 641 #else
644 return static_cast<Thread::LocalStorageKey>(pthread_key); 642 return static_cast<Thread::LocalStorageKey>(pthread_key);
645 #endif 643 #endif
646 } 644 }
647 645
648 646
649 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) { 647 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) {
650 #if defined(__CYGWIN__) 648 #if V8_OS_CYGWIN
651 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); 649 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
652 intptr_t ptr_key = static_cast<intptr_t>(local_key); 650 intptr_t ptr_key = static_cast<intptr_t>(local_key);
653 return reinterpret_cast<pthread_key_t>(ptr_key); 651 return reinterpret_cast<pthread_key_t>(ptr_key);
654 #else 652 #else
655 return static_cast<pthread_key_t>(local_key); 653 return static_cast<pthread_key_t>(local_key);
656 #endif 654 #endif
657 } 655 }
658 656
659 657
660 #ifdef V8_FAST_TLS_SUPPORTED 658 #ifdef V8_FAST_TLS_SUPPORTED
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 return ntohl(value); 988 return ntohl(value);
991 } 989 }
992 990
993 991
994 Socket* OS::CreateSocket() { 992 Socket* OS::CreateSocket() {
995 return new POSIXSocket(); 993 return new POSIXSocket();
996 } 994 }
997 995
998 996
999 } } // namespace v8::internal 997 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-posix.h ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698