diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-10-22 15:14:25 -0700 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-10-23 09:17:31 -0700 |
commit | a53c763c16eeabb0901a05dbcf38a72fa96d2f26 (patch) | |
tree | 309bf250e1521cedf0e945d7a7629db511e64498 /deps/v8/src/platform.h | |
parent | 54910044b33a6405c72ad085915a55c575c027fc (diff) | |
download | node-new-a53c763c16eeabb0901a05dbcf38a72fa96d2f26.tar.gz |
v8: upgrade 3.21.18.3
Diffstat (limited to 'deps/v8/src/platform.h')
-rw-r--r-- | deps/v8/src/platform.h | 251 |
1 files changed, 12 insertions, 239 deletions
diff --git a/deps/v8/src/platform.h b/deps/v8/src/platform.h index 8b27c19a65..ee8fb92910 100644 --- a/deps/v8/src/platform.h +++ b/deps/v8/src/platform.h @@ -44,6 +44,13 @@ #ifndef V8_PLATFORM_H_ #define V8_PLATFORM_H_ +#include <cstdarg> + +#include "platform/mutex.h" +#include "platform/semaphore.h" +#include "utils.h" +#include "v8globals.h" + #ifdef __sun # ifndef signbit namespace std { @@ -52,22 +59,8 @@ int signbit(double x); # endif #endif -// GCC specific stuff -#ifdef __GNUC__ - -// Needed for va_list on at least MinGW and Android. -#include <stdarg.h> - -#define __GNUC_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) - -#endif // __GNUC__ - - -// Windows specific stuff. -#ifdef WIN32 - // Microsoft Visual C++ specific stuff. -#ifdef _MSC_VER +#if V8_CC_MSVC #include "win32-headers.h" #include "win32-math.h" @@ -76,7 +69,7 @@ int strncasecmp(const char* s1, const char* s2, int n); inline int lrint(double flt) { int intgr; -#if defined(V8_TARGET_ARCH_IA32) +#if V8_TARGET_ARCH_IA32 __asm { fld flt fistp intgr @@ -91,25 +84,11 @@ inline int lrint(double flt) { return intgr; } -#endif // _MSC_VER - -#ifndef __CYGWIN__ -// Random is missing on both Visual Studio and MinGW. -int random(); -#endif - -#endif // WIN32 - -#include "lazy-instance.h" -#include "utils.h" -#include "v8globals.h" +#endif // V8_CC_MSVC namespace v8 { namespace internal { -class Semaphore; -class Mutex; - double ceiling(double x); double modulo(double x, double y); @@ -124,9 +103,6 @@ double fast_sqrt(double input); // on demand. void lazily_initialize_fast_exp(); -// Forward declarations. -class Socket; - // ---------------------------------------------------------------------------- // Fast TLS support @@ -190,26 +166,16 @@ inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { class OS { public: - // Initializes the platform OS support. Called once at VM startup. - static void SetUp(); - // Initializes the platform OS support that depend on CPU features. This is // called after CPU initialization. static void PostSetUp(); - // Clean up platform-OS-related things. Called once at VM shutdown. - static void TearDown(); - // Returns the accumulated user time for thread. This routine // can be used for profiling. The implementation should // strive for high-precision timer resolution, preferable // micro-second resolution. static int GetUserTime(uint32_t* secs, uint32_t* usecs); - // Get a tick counter normalized to one tick per microsecond. - // Used for calculating time intervals. - static int64_t Ticks(); - // Returns current time as the number of milliseconds since // 00:00:00 UTC, January 1, 1970. static double TimeCurrentMillis(); @@ -277,18 +243,9 @@ class OS { // Get the Alignment guaranteed by Allocate(). static size_t AllocateAlignment(); - // Returns an indication of whether a pointer is in a space that - // has been allocated by Allocate(). This method may conservatively - // always return false, but giving more accurate information may - // improve the robustness of the stack dump code in the presence of - // heap corruption. - static bool IsOutsideAllocatedSpace(void* pointer); - // Sleep for a number of milliseconds. static void Sleep(const int milliseconds); - static int NumberOfCores(); - // Abort the current process. static void Abort(); @@ -309,18 +266,6 @@ class OS { static int StackWalk(Vector<StackFrame> frames); - // Factory method for creating platform dependent Mutex. - // Please use delete to reclaim the storage for the returned Mutex. - static Mutex* CreateMutex(); - - // Factory method for creating platform dependent Semaphore. - // Please use delete to reclaim the storage for the returned Semaphore. - static Semaphore* CreateSemaphore(int count); - - // Factory method for creating platform dependent Socket. - // Please use delete to reclaim the storage for the returned Socket. - static Socket* CreateSocket(); - class MemoryMappedFile { public: static MemoryMappedFile* open(const char* name); @@ -342,7 +287,7 @@ class OS { // Support for the profiler. Can do nothing, in which case ticks // occuring in shared libraries will not be properly accounted for. - static void LogSharedLibraryAddresses(); + static void LogSharedLibraryAddresses(Isolate* isolate); // Support for the profiler. Notifies the external profiling // process that a code moving garbage collection starts. Can do @@ -365,22 +310,10 @@ class OS { // Returns the double constant NAN static double nan_value(); - // Support runtime detection of Cpu implementer - static CpuImplementer GetCpuImplementer(); - - // Support runtime detection of Cpu implementer - static CpuPart GetCpuPart(CpuImplementer implementer); - - // Support runtime detection of VFP3 on ARM CPUs. - static bool ArmCpuHasFeature(CpuFeature feature); - // Support runtime detection of whether the hard float option of the // EABI is used. static bool ArmUsingHardFloat(); - // Support runtime detection of FPU on MIPS CPUs. - static bool MipsCpuHasFeature(CpuFeature feature); - // Returns the activation frame alignment constraint or zero if // the platform doesn't care. Guaranteed to be a power of two. static int ActivationFrameAlignment(); @@ -547,59 +480,6 @@ class VirtualMemory { // ---------------------------------------------------------------------------- -// Semaphore -// -// A semaphore object is a synchronization object that maintains a count. The -// count is decremented each time a thread completes a wait for the semaphore -// object and incremented each time a thread signals the semaphore. When the -// count reaches zero, threads waiting for the semaphore blocks until the -// count becomes non-zero. - -class Semaphore { - public: - virtual ~Semaphore() {} - - // Suspends the calling thread until the semaphore counter is non zero - // and then decrements the semaphore counter. - virtual void Wait() = 0; - - // Suspends the calling thread until the counter is non zero or the timeout - // time has passed. If timeout happens the return value is false and the - // counter is unchanged. Otherwise the semaphore counter is decremented and - // true is returned. The timeout value is specified in microseconds. - virtual bool Wait(int timeout) = 0; - - // Increments the semaphore counter. - virtual void Signal() = 0; -}; - -template <int InitialValue> -struct CreateSemaphoreTrait { - static Semaphore* Create() { - return OS::CreateSemaphore(InitialValue); - } -}; - -// POD Semaphore initialized lazily (i.e. the first time Pointer() is called). -// Usage: -// // The following semaphore starts at 0. -// static LazySemaphore<0>::type my_semaphore = LAZY_SEMAPHORE_INITIALIZER; -// -// void my_function() { -// // Do something with my_semaphore.Pointer(). -// } -// -template <int InitialValue> -struct LazySemaphore { - typedef typename LazyDynamicInstance< - Semaphore, CreateSemaphoreTrait<InitialValue>, - ThreadSafeInitOnceTrait>::type type; -}; - -#define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER - - -// ---------------------------------------------------------------------------- // Thread // // Thread objects are used for creating and running threads. When the start() @@ -641,7 +521,7 @@ class Thread { // Start new thread and wait until Run() method is called on the new thread. void StartSynchronously() { - start_semaphore_ = OS::CreateSemaphore(0); + start_semaphore_ = new Semaphore(0); Start(); start_semaphore_->Wait(); delete start_semaphore_; @@ -714,113 +594,6 @@ class Thread { DISALLOW_COPY_AND_ASSIGN(Thread); }; - -// ---------------------------------------------------------------------------- -// Mutex -// -// Mutexes are used for serializing access to non-reentrant sections of code. -// The implementations of mutex should allow for nested/recursive locking. - -class Mutex { - public: - virtual ~Mutex() {} - - // Locks the given mutex. If the mutex is currently unlocked, it becomes - // locked and owned by the calling thread, and immediately. If the mutex - // is already locked by another thread, suspends the calling thread until - // the mutex is unlocked. - virtual int Lock() = 0; - - // Unlocks the given mutex. The mutex is assumed to be locked and owned by - // the calling thread on entrance. - virtual int Unlock() = 0; - - // Tries to lock the given mutex. Returns whether the mutex was - // successfully locked. - virtual bool TryLock() = 0; -}; - -struct CreateMutexTrait { - static Mutex* Create() { - return OS::CreateMutex(); - } -}; - -// POD Mutex initialized lazily (i.e. the first time Pointer() is called). -// Usage: -// static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER; -// -// void my_function() { -// ScopedLock my_lock(my_mutex.Pointer()); -// // Do something. -// } -// -typedef LazyDynamicInstance< - Mutex, CreateMutexTrait, ThreadSafeInitOnceTrait>::type LazyMutex; - -#define LAZY_MUTEX_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER - -// ---------------------------------------------------------------------------- -// ScopedLock -// -// Stack-allocated ScopedLocks provide block-scoped locking and -// unlocking of a mutex. -class ScopedLock { - public: - explicit ScopedLock(Mutex* mutex): mutex_(mutex) { - ASSERT(mutex_ != NULL); - mutex_->Lock(); - } - ~ScopedLock() { - mutex_->Unlock(); - } - - private: - Mutex* mutex_; - DISALLOW_COPY_AND_ASSIGN(ScopedLock); -}; - - -// ---------------------------------------------------------------------------- -// Socket -// - -class Socket { - public: - virtual ~Socket() {} - - // Server initialization. - virtual bool Bind(const int port) = 0; - virtual bool Listen(int backlog) const = 0; - virtual Socket* Accept() const = 0; - - // Client initialization. - virtual bool Connect(const char* host, const char* port) = 0; - - // Shutdown socket for both read and write. This causes blocking Send and - // Receive calls to exit. After Shutdown the Socket object cannot be used for - // any communication. - virtual bool Shutdown() = 0; - - // Data Transimission - // Return 0 on failure. - virtual int Send(const char* data, int len) const = 0; - virtual int Receive(char* data, int len) const = 0; - - // Set the value of the SO_REUSEADDR socket option. - virtual bool SetReuseAddress(bool reuse_address) = 0; - - virtual bool IsValid() const = 0; - - static bool SetUp(); - static int LastError(); - static uint16_t HToN(uint16_t value); - static uint16_t NToH(uint16_t value); - static uint32_t HToN(uint32_t value); - static uint32_t NToH(uint32_t value); -}; - - } } // namespace v8::internal #endif // V8_PLATFORM_H_ |