OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project 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 // Platform-specific code for POSIX goes here. This is not a platform on its | 5 // Platform-specific code for POSIX goes here. This is not a platform on its |
6 // own, but contains the parts which are the same across the POSIX platforms | 6 // own, but contains the parts which are the same across the POSIX platforms |
7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. | 7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. |
8 | 8 |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <pthread.h> | 10 #include <pthread.h> |
(...skipping 27 matching lines...) Expand all Loading... |
38 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) | 38 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
39 #define LOG_TAG "v8" | 39 #define LOG_TAG "v8" |
40 #include <android/log.h> | 40 #include <android/log.h> |
41 #endif | 41 #endif |
42 | 42 |
43 #include "src/v8.h" | 43 #include "src/v8.h" |
44 | 44 |
45 #include "src/isolate-inl.h" | 45 #include "src/isolate-inl.h" |
46 #include "src/platform.h" | 46 #include "src/platform.h" |
47 | 47 |
| 48 #ifdef V8_FAST_TLS_SUPPORTED |
| 49 #include "src/base/atomicops.h" |
| 50 #endif |
| 51 |
48 namespace v8 { | 52 namespace v8 { |
49 namespace internal { | 53 namespace internal { |
50 | 54 |
51 // 0 is never a valid thread id. | 55 // 0 is never a valid thread id. |
52 static const pthread_t kNoThread = (pthread_t) 0; | 56 static const pthread_t kNoThread = (pthread_t) 0; |
53 | 57 |
54 | 58 |
55 unsigned OS::CpuFeaturesImpliedByPlatform() { | 59 unsigned OS::CpuFeaturesImpliedByPlatform() { |
56 return 0; // Nothing special. | 60 return 0; // Nothing special. |
57 } | 61 } |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 intptr_t ptr_key = static_cast<intptr_t>(local_key); | 596 intptr_t ptr_key = static_cast<intptr_t>(local_key); |
593 return reinterpret_cast<pthread_key_t>(ptr_key); | 597 return reinterpret_cast<pthread_key_t>(ptr_key); |
594 #else | 598 #else |
595 return static_cast<pthread_key_t>(local_key); | 599 return static_cast<pthread_key_t>(local_key); |
596 #endif | 600 #endif |
597 } | 601 } |
598 | 602 |
599 | 603 |
600 #ifdef V8_FAST_TLS_SUPPORTED | 604 #ifdef V8_FAST_TLS_SUPPORTED |
601 | 605 |
602 static Atomic32 tls_base_offset_initialized = 0; | 606 static base::Atomic32 tls_base_offset_initialized = 0; |
603 intptr_t kMacTlsBaseOffset = 0; | 607 intptr_t kMacTlsBaseOffset = 0; |
604 | 608 |
605 // It's safe to do the initialization more that once, but it has to be | 609 // It's safe to do the initialization more that once, but it has to be |
606 // done at least once. | 610 // done at least once. |
607 static void InitializeTlsBaseOffset() { | 611 static void InitializeTlsBaseOffset() { |
608 const size_t kBufferSize = 128; | 612 const size_t kBufferSize = 128; |
609 char buffer[kBufferSize]; | 613 char buffer[kBufferSize]; |
610 size_t buffer_size = kBufferSize; | 614 size_t buffer_size = kBufferSize; |
611 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; | 615 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; |
612 if (sysctl(ctl_name, 2, buffer, &buffer_size, NULL, 0) != 0) { | 616 if (sysctl(ctl_name, 2, buffer, &buffer_size, NULL, 0) != 0) { |
(...skipping 15 matching lines...) Expand all Loading... |
628 #if V8_HOST_ARCH_IA32 | 632 #if V8_HOST_ARCH_IA32 |
629 kMacTlsBaseOffset = 0x48; | 633 kMacTlsBaseOffset = 0x48; |
630 #else | 634 #else |
631 kMacTlsBaseOffset = 0x60; | 635 kMacTlsBaseOffset = 0x60; |
632 #endif | 636 #endif |
633 } else { | 637 } else { |
634 // 11.x.x (Lion) changed the offset. | 638 // 11.x.x (Lion) changed the offset. |
635 kMacTlsBaseOffset = 0; | 639 kMacTlsBaseOffset = 0; |
636 } | 640 } |
637 | 641 |
638 Release_Store(&tls_base_offset_initialized, 1); | 642 base::Release_Store(&tls_base_offset_initialized, 1); |
639 } | 643 } |
640 | 644 |
641 | 645 |
642 static void CheckFastTls(Thread::LocalStorageKey key) { | 646 static void CheckFastTls(Thread::LocalStorageKey key) { |
643 void* expected = reinterpret_cast<void*>(0x1234CAFE); | 647 void* expected = reinterpret_cast<void*>(0x1234CAFE); |
644 Thread::SetThreadLocal(key, expected); | 648 Thread::SetThreadLocal(key, expected); |
645 void* actual = Thread::GetExistingThreadLocal(key); | 649 void* actual = Thread::GetExistingThreadLocal(key); |
646 if (expected != actual) { | 650 if (expected != actual) { |
647 V8_Fatal(__FILE__, __LINE__, | 651 V8_Fatal(__FILE__, __LINE__, |
648 "V8 failed to initialize fast TLS on current kernel"); | 652 "V8 failed to initialize fast TLS on current kernel"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 694 |
691 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 695 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
692 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 696 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
693 int result = pthread_setspecific(pthread_key, value); | 697 int result = pthread_setspecific(pthread_key, value); |
694 ASSERT_EQ(0, result); | 698 ASSERT_EQ(0, result); |
695 USE(result); | 699 USE(result); |
696 } | 700 } |
697 | 701 |
698 | 702 |
699 } } // namespace v8::internal | 703 } } // namespace v8::internal |
OLD | NEW |