| OLD | NEW |
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 #endif // _MSC_VER | 94 #endif // _MSC_VER |
| 95 | 95 |
| 96 #ifndef __CYGWIN__ | 96 #ifndef __CYGWIN__ |
| 97 // Random is missing on both Visual Studio and MinGW. | 97 // Random is missing on both Visual Studio and MinGW. |
| 98 int random(); | 98 int random(); |
| 99 #endif | 99 #endif |
| 100 | 100 |
| 101 #endif // WIN32 | 101 #endif // WIN32 |
| 102 | 102 |
| 103 #include "lazy-instance.h" | 103 #include "lazy-instance.h" |
| 104 #include "synchronization/mutex.h" |
| 104 #include "utils.h" | 105 #include "utils.h" |
| 105 #include "v8globals.h" | 106 #include "v8globals.h" |
| 106 | 107 |
| 107 namespace v8 { | 108 namespace v8 { |
| 108 namespace internal { | 109 namespace internal { |
| 109 | 110 |
| 110 class Semaphore; | 111 class Semaphore; |
| 111 class Mutex; | |
| 112 | 112 |
| 113 double ceiling(double x); | 113 double ceiling(double x); |
| 114 double modulo(double x, double y); | 114 double modulo(double x, double y); |
| 115 | 115 |
| 116 // Custom implementation of math functions. | 116 // Custom implementation of math functions. |
| 117 double fast_sin(double input); | 117 double fast_sin(double input); |
| 118 double fast_cos(double input); | 118 double fast_cos(double input); |
| 119 double fast_tan(double input); | 119 double fast_tan(double input); |
| 120 double fast_log(double input); | 120 double fast_log(double input); |
| 121 double fast_exp(double input); | 121 double fast_exp(double input); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 static const int kStackWalkError = -1; | 302 static const int kStackWalkError = -1; |
| 303 static const int kStackWalkMaxNameLen = 256; | 303 static const int kStackWalkMaxNameLen = 256; |
| 304 static const int kStackWalkMaxTextLen = 256; | 304 static const int kStackWalkMaxTextLen = 256; |
| 305 struct StackFrame { | 305 struct StackFrame { |
| 306 void* address; | 306 void* address; |
| 307 char text[kStackWalkMaxTextLen]; | 307 char text[kStackWalkMaxTextLen]; |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 static int StackWalk(Vector<StackFrame> frames); | 310 static int StackWalk(Vector<StackFrame> frames); |
| 311 | 311 |
| 312 // Factory method for creating platform dependent Mutex. | |
| 313 // Please use delete to reclaim the storage for the returned Mutex. | |
| 314 static Mutex* CreateMutex(); | |
| 315 | |
| 316 // Factory method for creating platform dependent Semaphore. | 312 // Factory method for creating platform dependent Semaphore. |
| 317 // Please use delete to reclaim the storage for the returned Semaphore. | 313 // Please use delete to reclaim the storage for the returned Semaphore. |
| 318 static Semaphore* CreateSemaphore(int count); | 314 static Semaphore* CreateSemaphore(int count); |
| 319 | 315 |
| 320 // Factory method for creating platform dependent Socket. | 316 // Factory method for creating platform dependent Socket. |
| 321 // Please use delete to reclaim the storage for the returned Socket. | 317 // Please use delete to reclaim the storage for the returned Socket. |
| 322 static Socket* CreateSocket(); | 318 static Socket* CreateSocket(); |
| 323 | 319 |
| 324 class MemoryMappedFile { | 320 class MemoryMappedFile { |
| 325 public: | 321 public: |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 693 |
| 698 char name_[kMaxThreadNameLength]; | 694 char name_[kMaxThreadNameLength]; |
| 699 int stack_size_; | 695 int stack_size_; |
| 700 Semaphore* start_semaphore_; | 696 Semaphore* start_semaphore_; |
| 701 | 697 |
| 702 DISALLOW_COPY_AND_ASSIGN(Thread); | 698 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 703 }; | 699 }; |
| 704 | 700 |
| 705 | 701 |
| 706 // ---------------------------------------------------------------------------- | 702 // ---------------------------------------------------------------------------- |
| 707 // Mutex | |
| 708 // | |
| 709 // Mutexes are used for serializing access to non-reentrant sections of code. | |
| 710 // The implementations of mutex should allow for nested/recursive locking. | |
| 711 | |
| 712 class Mutex { | |
| 713 public: | |
| 714 virtual ~Mutex() {} | |
| 715 | |
| 716 // Locks the given mutex. If the mutex is currently unlocked, it becomes | |
| 717 // locked and owned by the calling thread, and immediately. If the mutex | |
| 718 // is already locked by another thread, suspends the calling thread until | |
| 719 // the mutex is unlocked. | |
| 720 virtual int Lock() = 0; | |
| 721 | |
| 722 // Unlocks the given mutex. The mutex is assumed to be locked and owned by | |
| 723 // the calling thread on entrance. | |
| 724 virtual int Unlock() = 0; | |
| 725 | |
| 726 // Tries to lock the given mutex. Returns whether the mutex was | |
| 727 // successfully locked. | |
| 728 virtual bool TryLock() = 0; | |
| 729 }; | |
| 730 | |
| 731 struct CreateMutexTrait { | |
| 732 static Mutex* Create() { | |
| 733 return OS::CreateMutex(); | |
| 734 } | |
| 735 }; | |
| 736 | |
| 737 // POD Mutex initialized lazily (i.e. the first time Pointer() is called). | |
| 738 // Usage: | |
| 739 // static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER; | |
| 740 // | |
| 741 // void my_function() { | |
| 742 // ScopedLock my_lock(my_mutex.Pointer()); | |
| 743 // // Do something. | |
| 744 // } | |
| 745 // | |
| 746 typedef LazyDynamicInstance< | |
| 747 Mutex, CreateMutexTrait, ThreadSafeInitOnceTrait>::type LazyMutex; | |
| 748 | |
| 749 #define LAZY_MUTEX_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER | |
| 750 | |
| 751 // ---------------------------------------------------------------------------- | |
| 752 // ScopedLock | |
| 753 // | |
| 754 // Stack-allocated ScopedLocks provide block-scoped locking and | |
| 755 // unlocking of a mutex. | |
| 756 class ScopedLock { | |
| 757 public: | |
| 758 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { | |
| 759 ASSERT(mutex_ != NULL); | |
| 760 mutex_->Lock(); | |
| 761 } | |
| 762 ~ScopedLock() { | |
| 763 mutex_->Unlock(); | |
| 764 } | |
| 765 | |
| 766 private: | |
| 767 Mutex* mutex_; | |
| 768 DISALLOW_COPY_AND_ASSIGN(ScopedLock); | |
| 769 }; | |
| 770 | |
| 771 | |
| 772 // ---------------------------------------------------------------------------- | |
| 773 // Socket | 703 // Socket |
| 774 // | 704 // |
| 775 | 705 |
| 776 class Socket { | 706 class Socket { |
| 777 public: | 707 public: |
| 778 virtual ~Socket() {} | 708 virtual ~Socket() {} |
| 779 | 709 |
| 780 // Server initialization. | 710 // Server initialization. |
| 781 virtual bool Bind(const int port) = 0; | 711 virtual bool Bind(const int port) = 0; |
| 782 virtual bool Listen(int backlog) const = 0; | 712 virtual bool Listen(int backlog) const = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 805 static uint16_t HToN(uint16_t value); | 735 static uint16_t HToN(uint16_t value); |
| 806 static uint16_t NToH(uint16_t value); | 736 static uint16_t NToH(uint16_t value); |
| 807 static uint32_t HToN(uint32_t value); | 737 static uint32_t HToN(uint32_t value); |
| 808 static uint32_t NToH(uint32_t value); | 738 static uint32_t NToH(uint32_t value); |
| 809 }; | 739 }; |
| 810 | 740 |
| 811 | 741 |
| 812 } } // namespace v8::internal | 742 } } // namespace v8::internal |
| 813 | 743 |
| 814 #endif // V8_PLATFORM_H_ | 744 #endif // V8_PLATFORM_H_ |
| OLD | NEW |