| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 int strncasecmp(const char* s1, const char* s2, int n); | 72 int strncasecmp(const char* s1, const char* s2, int n); |
| 73 | 73 |
| 74 #endif // _MSC_VER | 74 #endif // _MSC_VER |
| 75 | 75 |
| 76 // Random is missing on both Visual Studio and MinGW. | 76 // Random is missing on both Visual Studio and MinGW. |
| 77 int random(); | 77 int random(); |
| 78 | 78 |
| 79 #endif // WIN32 | 79 #endif // WIN32 |
| 80 | 80 |
| 81 #include "atomicops.h" | 81 #include "atomicops.h" |
| 82 #include "lazy-instance.h" |
| 82 #include "platform-tls.h" | 83 #include "platform-tls.h" |
| 83 #include "utils.h" | 84 #include "utils.h" |
| 84 #include "v8globals.h" | 85 #include "v8globals.h" |
| 85 | 86 |
| 86 namespace v8 { | 87 namespace v8 { |
| 87 namespace internal { | 88 namespace internal { |
| 88 | 89 |
| 89 // Use AtomicWord for a machine-sized pointer. It is assumed that | 90 // Use AtomicWord for a machine-sized pointer. It is assumed that |
| 90 // reads and writes of naturally aligned values of this type are atomic. | 91 // reads and writes of naturally aligned values of this type are atomic. |
| 91 typedef intptr_t AtomicWord; | 92 typedef intptr_t AtomicWord; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 513 |
| 513 // Unlocks the given mutex. The mutex is assumed to be locked and owned by | 514 // Unlocks the given mutex. The mutex is assumed to be locked and owned by |
| 514 // the calling thread on entrance. | 515 // the calling thread on entrance. |
| 515 virtual int Unlock() = 0; | 516 virtual int Unlock() = 0; |
| 516 | 517 |
| 517 // Tries to lock the given mutex. Returns whether the mutex was | 518 // Tries to lock the given mutex. Returns whether the mutex was |
| 518 // successfully locked. | 519 // successfully locked. |
| 519 virtual bool TryLock() = 0; | 520 virtual bool TryLock() = 0; |
| 520 }; | 521 }; |
| 521 | 522 |
| 523 struct CreateMutexTrait { |
| 524 static Mutex* Create() { |
| 525 return OS::CreateMutex(); |
| 526 } |
| 527 }; |
| 528 |
| 529 // POD Mutex initialized lazily (i.e. the first time Pointer() is called). |
| 530 // Usage: |
| 531 // static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER; |
| 532 // |
| 533 // void my_function() { |
| 534 // ScopedLock my_lock(my_mutex.Pointer()); |
| 535 // // Do something. |
| 536 // } |
| 537 // |
| 538 typedef LazyDynamicInstance<Mutex, CreateMutexTrait>::type LazyMutex; |
| 539 |
| 540 #define LAZY_MUTEX_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER |
| 522 | 541 |
| 523 // ---------------------------------------------------------------------------- | 542 // ---------------------------------------------------------------------------- |
| 524 // ScopedLock | 543 // ScopedLock |
| 525 // | 544 // |
| 526 // Stack-allocated ScopedLocks provide block-scoped locking and | 545 // Stack-allocated ScopedLocks provide block-scoped locking and |
| 527 // unlocking of a mutex. | 546 // unlocking of a mutex. |
| 528 class ScopedLock { | 547 class ScopedLock { |
| 529 public: | 548 public: |
| 530 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { | 549 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { |
| 531 ASSERT(mutex_ != NULL); | 550 ASSERT(mutex_ != NULL); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 561 // Suspends the calling thread until the counter is non zero or the timeout | 580 // Suspends the calling thread until the counter is non zero or the timeout |
| 562 // time has passed. If timeout happens the return value is false and the | 581 // time has passed. If timeout happens the return value is false and the |
| 563 // counter is unchanged. Otherwise the semaphore counter is decremented and | 582 // counter is unchanged. Otherwise the semaphore counter is decremented and |
| 564 // true is returned. The timeout value is specified in microseconds. | 583 // true is returned. The timeout value is specified in microseconds. |
| 565 virtual bool Wait(int timeout) = 0; | 584 virtual bool Wait(int timeout) = 0; |
| 566 | 585 |
| 567 // Increments the semaphore counter. | 586 // Increments the semaphore counter. |
| 568 virtual void Signal() = 0; | 587 virtual void Signal() = 0; |
| 569 }; | 588 }; |
| 570 | 589 |
| 590 template <int InitialValue> |
| 591 struct CreateSemaphoreTrait { |
| 592 static Semaphore* Create() { |
| 593 return OS::CreateSemaphore(InitialValue); |
| 594 } |
| 595 }; |
| 596 |
| 597 // POD Semaphore initialized lazily (i.e. the first time Pointer() is called). |
| 598 // Usage: |
| 599 // // The following semaphore starts at 0. |
| 600 // static LazySemaphore<0>::type my_semaphore = LAZY_SEMAPHORE_INITIALIZER; |
| 601 // |
| 602 // void my_function() { |
| 603 // // Do something with my_semaphore.Pointer(). |
| 604 // } |
| 605 // |
| 606 template <int InitialValue> |
| 607 struct LazySemaphore { |
| 608 typedef typename LazyDynamicInstance< |
| 609 Semaphore, CreateSemaphoreTrait<InitialValue> >::type type; |
| 610 }; |
| 611 |
| 612 #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER |
| 613 |
| 571 | 614 |
| 572 // ---------------------------------------------------------------------------- | 615 // ---------------------------------------------------------------------------- |
| 573 // Socket | 616 // Socket |
| 574 // | 617 // |
| 575 | 618 |
| 576 class Socket { | 619 class Socket { |
| 577 public: | 620 public: |
| 578 virtual ~Socket() {} | 621 virtual ~Socket() {} |
| 579 | 622 |
| 580 // Server initialization. | 623 // Server initialization. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 Atomic32 active_; | 737 Atomic32 active_; |
| 695 PlatformData* data_; // Platform specific data. | 738 PlatformData* data_; // Platform specific data. |
| 696 int samples_taken_; // Counts stack samples taken. | 739 int samples_taken_; // Counts stack samples taken. |
| 697 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 740 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
| 698 }; | 741 }; |
| 699 | 742 |
| 700 | 743 |
| 701 } } // namespace v8::internal | 744 } } // namespace v8::internal |
| 702 | 745 |
| 703 #endif // V8_PLATFORM_H_ | 746 #endif // V8_PLATFORM_H_ |
| OLD | NEW |