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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 return pthread_getspecific(pthread_key); | 567 return pthread_getspecific(pthread_key); |
568 } | 568 } |
569 | 569 |
570 | 570 |
571 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 571 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
572 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 572 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
573 pthread_setspecific(pthread_key, value); | 573 pthread_setspecific(pthread_key, value); |
574 } | 574 } |
575 | 575 |
576 | 576 |
577 void Thread::YieldCPU() { | |
578 sched_yield(); | |
579 } | |
580 | |
581 | |
582 class CygwinMutex : public Mutex { | |
583 public: | |
584 CygwinMutex() { | |
585 pthread_mutexattr_t attrs; | |
586 memset(&attrs, 0, sizeof(attrs)); | |
587 | |
588 int result = pthread_mutexattr_init(&attrs); | |
589 ASSERT(result == 0); | |
590 result = pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE); | |
591 ASSERT(result == 0); | |
592 result = pthread_mutex_init(&mutex_, &attrs); | |
593 ASSERT(result == 0); | |
594 } | |
595 | |
596 virtual ~CygwinMutex() { pthread_mutex_destroy(&mutex_); } | |
597 | |
598 virtual int Lock() { | |
599 int result = pthread_mutex_lock(&mutex_); | |
600 return result; | |
601 } | |
602 | |
603 virtual int Unlock() { | |
604 int result = pthread_mutex_unlock(&mutex_); | |
605 return result; | |
606 } | |
607 | |
608 virtual bool TryLock() { | |
609 int result = pthread_mutex_trylock(&mutex_); | |
610 // Return false if the lock is busy and locking failed. | |
611 if (result == EBUSY) { | |
612 return false; | |
613 } | |
614 ASSERT(result == 0); // Verify no other errors. | |
615 return true; | |
616 } | |
617 | |
618 private: | |
619 pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms. | |
620 }; | |
621 | |
622 | |
623 Mutex* OS::CreateMutex() { | |
624 return new CygwinMutex(); | |
625 } | |
626 | |
627 | |
628 class CygwinSemaphore : public Semaphore { | 577 class CygwinSemaphore : public Semaphore { |
629 public: | 578 public: |
630 explicit CygwinSemaphore(int count) { sem_init(&sem_, 0, count); } | 579 explicit CygwinSemaphore(int count) { sem_init(&sem_, 0, count); } |
631 virtual ~CygwinSemaphore() { sem_destroy(&sem_); } | 580 virtual ~CygwinSemaphore() { sem_destroy(&sem_); } |
632 | 581 |
633 virtual void Wait(); | 582 virtual void Wait(); |
634 virtual bool Wait(int timeout); | 583 virtual bool Wait(int timeout); |
635 virtual void Signal() { sem_post(&sem_); } | 584 virtual void Signal() { sem_post(&sem_); } |
636 private: | 585 private: |
637 sem_t sem_; | 586 sem_t sem_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 limit_mutex = CreateMutex(); | 650 limit_mutex = CreateMutex(); |
702 } | 651 } |
703 | 652 |
704 | 653 |
705 void OS::TearDown() { | 654 void OS::TearDown() { |
706 delete limit_mutex; | 655 delete limit_mutex; |
707 } | 656 } |
708 | 657 |
709 | 658 |
710 } } // namespace v8::internal | 659 } } // namespace v8::internal |
OLD | NEW |