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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 return pthread_getspecific(pthread_key); | 561 return pthread_getspecific(pthread_key); |
562 } | 562 } |
563 | 563 |
564 | 564 |
565 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 565 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
566 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); | 566 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); |
567 pthread_setspecific(pthread_key, value); | 567 pthread_setspecific(pthread_key, value); |
568 } | 568 } |
569 | 569 |
570 | 570 |
571 void Thread::YieldCPU() { | |
572 sched_yield(); | |
573 } | |
574 | |
575 | |
576 class FreeBSDMutex : public Mutex { | |
577 public: | |
578 FreeBSDMutex() { | |
579 pthread_mutexattr_t attrs; | |
580 int result = pthread_mutexattr_init(&attrs); | |
581 ASSERT(result == 0); | |
582 result = pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE); | |
583 ASSERT(result == 0); | |
584 result = pthread_mutex_init(&mutex_, &attrs); | |
585 ASSERT(result == 0); | |
586 USE(result); | |
587 } | |
588 | |
589 virtual ~FreeBSDMutex() { pthread_mutex_destroy(&mutex_); } | |
590 | |
591 virtual int Lock() { | |
592 int result = pthread_mutex_lock(&mutex_); | |
593 return result; | |
594 } | |
595 | |
596 virtual int Unlock() { | |
597 int result = pthread_mutex_unlock(&mutex_); | |
598 return result; | |
599 } | |
600 | |
601 virtual bool TryLock() { | |
602 int result = pthread_mutex_trylock(&mutex_); | |
603 // Return false if the lock is busy and locking failed. | |
604 if (result == EBUSY) { | |
605 return false; | |
606 } | |
607 ASSERT(result == 0); // Verify no other errors. | |
608 return true; | |
609 } | |
610 | |
611 private: | |
612 pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms. | |
613 }; | |
614 | |
615 | |
616 Mutex* OS::CreateMutex() { | |
617 return new FreeBSDMutex(); | |
618 } | |
619 | |
620 | |
621 class FreeBSDSemaphore : public Semaphore { | 571 class FreeBSDSemaphore : public Semaphore { |
622 public: | 572 public: |
623 explicit FreeBSDSemaphore(int count) { sem_init(&sem_, 0, count); } | 573 explicit FreeBSDSemaphore(int count) { sem_init(&sem_, 0, count); } |
624 virtual ~FreeBSDSemaphore() { sem_destroy(&sem_); } | 574 virtual ~FreeBSDSemaphore() { sem_destroy(&sem_); } |
625 | 575 |
626 virtual void Wait(); | 576 virtual void Wait(); |
627 virtual bool Wait(int timeout); | 577 virtual bool Wait(int timeout); |
628 virtual void Signal() { sem_post(&sem_); } | 578 virtual void Signal() { sem_post(&sem_); } |
629 private: | 579 private: |
630 sem_t sem_; | 580 sem_t sem_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 limit_mutex = CreateMutex(); | 635 limit_mutex = CreateMutex(); |
686 } | 636 } |
687 | 637 |
688 | 638 |
689 void OS::TearDown() { | 639 void OS::TearDown() { |
690 delete limit_mutex; | 640 delete limit_mutex; |
691 } | 641 } |
692 | 642 |
693 | 643 |
694 } } // namespace v8::internal | 644 } } // namespace v8::internal |
OLD | NEW |