| 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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 return pthread_getspecific(pthread_key); | 600 return pthread_getspecific(pthread_key); |
| 601 } | 601 } |
| 602 | 602 |
| 603 | 603 |
| 604 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 604 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
| 605 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); | 605 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); |
| 606 pthread_setspecific(pthread_key, value); | 606 pthread_setspecific(pthread_key, value); |
| 607 } | 607 } |
| 608 | 608 |
| 609 | 609 |
| 610 void Thread::YieldCPU() { | |
| 611 sched_yield(); | |
| 612 } | |
| 613 | |
| 614 | |
| 615 class OpenBSDMutex : public Mutex { | |
| 616 public: | |
| 617 OpenBSDMutex() { | |
| 618 pthread_mutexattr_t attrs; | |
| 619 int result = pthread_mutexattr_init(&attrs); | |
| 620 ASSERT(result == 0); | |
| 621 result = pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE); | |
| 622 ASSERT(result == 0); | |
| 623 result = pthread_mutex_init(&mutex_, &attrs); | |
| 624 ASSERT(result == 0); | |
| 625 USE(result); | |
| 626 } | |
| 627 | |
| 628 virtual ~OpenBSDMutex() { pthread_mutex_destroy(&mutex_); } | |
| 629 | |
| 630 virtual int Lock() { | |
| 631 int result = pthread_mutex_lock(&mutex_); | |
| 632 return result; | |
| 633 } | |
| 634 | |
| 635 virtual int Unlock() { | |
| 636 int result = pthread_mutex_unlock(&mutex_); | |
| 637 return result; | |
| 638 } | |
| 639 | |
| 640 virtual bool TryLock() { | |
| 641 int result = pthread_mutex_trylock(&mutex_); | |
| 642 // Return false if the lock is busy and locking failed. | |
| 643 if (result == EBUSY) { | |
| 644 return false; | |
| 645 } | |
| 646 ASSERT(result == 0); // Verify no other errors. | |
| 647 return true; | |
| 648 } | |
| 649 | |
| 650 private: | |
| 651 pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms. | |
| 652 }; | |
| 653 | |
| 654 | |
| 655 Mutex* OS::CreateMutex() { | |
| 656 return new OpenBSDMutex(); | |
| 657 } | |
| 658 | |
| 659 | |
| 660 class OpenBSDSemaphore : public Semaphore { | 610 class OpenBSDSemaphore : public Semaphore { |
| 661 public: | 611 public: |
| 662 explicit OpenBSDSemaphore(int count) { sem_init(&sem_, 0, count); } | 612 explicit OpenBSDSemaphore(int count) { sem_init(&sem_, 0, count); } |
| 663 virtual ~OpenBSDSemaphore() { sem_destroy(&sem_); } | 613 virtual ~OpenBSDSemaphore() { sem_destroy(&sem_); } |
| 664 | 614 |
| 665 virtual void Wait(); | 615 virtual void Wait(); |
| 666 virtual bool Wait(int timeout); | 616 virtual bool Wait(int timeout); |
| 667 virtual void Signal() { sem_post(&sem_); } | 617 virtual void Signal() { sem_post(&sem_); } |
| 668 private: | 618 private: |
| 669 sem_t sem_; | 619 sem_t sem_; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 limit_mutex = CreateMutex(); | 683 limit_mutex = CreateMutex(); |
| 734 } | 684 } |
| 735 | 685 |
| 736 | 686 |
| 737 void OS::TearDown() { | 687 void OS::TearDown() { |
| 738 delete limit_mutex; | 688 delete limit_mutex; |
| 739 } | 689 } |
| 740 | 690 |
| 741 | 691 |
| 742 } } // namespace v8::internal | 692 } } // namespace v8::internal |
| OLD | NEW |