| 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 20 matching lines...) Expand all Loading... |
| 31 #ifdef __sparc | 31 #ifdef __sparc |
| 32 # error "V8 does not support the SPARC CPU architecture." | 32 # error "V8 does not support the SPARC CPU architecture." |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 #include <sys/stack.h> // for stack alignment | 35 #include <sys/stack.h> // for stack alignment |
| 36 #include <unistd.h> // getpagesize(), usleep() | 36 #include <unistd.h> // getpagesize(), usleep() |
| 37 #include <sys/mman.h> // mmap() | 37 #include <sys/mman.h> // mmap() |
| 38 #include <ucontext.h> // walkstack(), getcontext() | 38 #include <ucontext.h> // walkstack(), getcontext() |
| 39 #include <dlfcn.h> // dladdr | 39 #include <dlfcn.h> // dladdr |
| 40 #include <pthread.h> | 40 #include <pthread.h> |
| 41 #include <sched.h> // for sched_yield | |
| 42 #include <semaphore.h> | 41 #include <semaphore.h> |
| 43 #include <time.h> | 42 #include <time.h> |
| 44 #include <sys/time.h> // gettimeofday(), timeradd() | 43 #include <sys/time.h> // gettimeofday(), timeradd() |
| 45 #include <errno.h> | 44 #include <errno.h> |
| 46 #include <ieeefp.h> // finite() | 45 #include <ieeefp.h> // finite() |
| 47 #include <signal.h> // sigemptyset(), etc | 46 #include <signal.h> // sigemptyset(), etc |
| 48 #include <sys/regset.h> | 47 #include <sys/regset.h> |
| 49 | 48 |
| 50 | 49 |
| 51 #undef MAP_TYPE | 50 #undef MAP_TYPE |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 return pthread_getspecific(pthread_key); | 531 return pthread_getspecific(pthread_key); |
| 533 } | 532 } |
| 534 | 533 |
| 535 | 534 |
| 536 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 535 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
| 537 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); | 536 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); |
| 538 pthread_setspecific(pthread_key, value); | 537 pthread_setspecific(pthread_key, value); |
| 539 } | 538 } |
| 540 | 539 |
| 541 | 540 |
| 542 void Thread::YieldCPU() { | |
| 543 sched_yield(); | |
| 544 } | |
| 545 | |
| 546 | |
| 547 class SolarisMutex : public Mutex { | |
| 548 public: | |
| 549 SolarisMutex() { | |
| 550 pthread_mutexattr_t attr; | |
| 551 pthread_mutexattr_init(&attr); | |
| 552 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); | |
| 553 pthread_mutex_init(&mutex_, &attr); | |
| 554 } | |
| 555 | |
| 556 ~SolarisMutex() { pthread_mutex_destroy(&mutex_); } | |
| 557 | |
| 558 int Lock() { return pthread_mutex_lock(&mutex_); } | |
| 559 | |
| 560 int Unlock() { return pthread_mutex_unlock(&mutex_); } | |
| 561 | |
| 562 virtual bool TryLock() { | |
| 563 int result = pthread_mutex_trylock(&mutex_); | |
| 564 // Return false if the lock is busy and locking failed. | |
| 565 if (result == EBUSY) { | |
| 566 return false; | |
| 567 } | |
| 568 ASSERT(result == 0); // Verify no other errors. | |
| 569 return true; | |
| 570 } | |
| 571 | |
| 572 private: | |
| 573 pthread_mutex_t mutex_; | |
| 574 }; | |
| 575 | |
| 576 | |
| 577 Mutex* OS::CreateMutex() { | |
| 578 return new SolarisMutex(); | |
| 579 } | |
| 580 | |
| 581 | |
| 582 class SolarisSemaphore : public Semaphore { | 541 class SolarisSemaphore : public Semaphore { |
| 583 public: | 542 public: |
| 584 explicit SolarisSemaphore(int count) { sem_init(&sem_, 0, count); } | 543 explicit SolarisSemaphore(int count) { sem_init(&sem_, 0, count); } |
| 585 virtual ~SolarisSemaphore() { sem_destroy(&sem_); } | 544 virtual ~SolarisSemaphore() { sem_destroy(&sem_); } |
| 586 | 545 |
| 587 virtual void Wait(); | 546 virtual void Wait(); |
| 588 virtual bool Wait(int timeout); | 547 virtual bool Wait(int timeout); |
| 589 virtual void Signal() { sem_post(&sem_); } | 548 virtual void Signal() { sem_post(&sem_); } |
| 590 private: | 549 private: |
| 591 sem_t sem_; | 550 sem_t sem_; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 limit_mutex = CreateMutex(); | 627 limit_mutex = CreateMutex(); |
| 669 } | 628 } |
| 670 | 629 |
| 671 | 630 |
| 672 void OS::TearDown() { | 631 void OS::TearDown() { |
| 673 delete limit_mutex; | 632 delete limit_mutex; |
| 674 } | 633 } |
| 675 | 634 |
| 676 | 635 |
| 677 } } // namespace v8::internal | 636 } } // namespace v8::internal |
| OLD | NEW |