| 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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 749 | 749 | 
| 750 | 750 | 
| 751 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 751 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 
| 752   pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 752   pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 
| 753   int result = pthread_setspecific(pthread_key, value); | 753   int result = pthread_setspecific(pthread_key, value); | 
| 754   ASSERT_EQ(0, result); | 754   ASSERT_EQ(0, result); | 
| 755   USE(result); | 755   USE(result); | 
| 756 } | 756 } | 
| 757 | 757 | 
| 758 | 758 | 
| 759 class POSIXMutex : public Mutex { |  | 
| 760  public: |  | 
| 761   POSIXMutex() { |  | 
| 762     pthread_mutexattr_t attr; |  | 
| 763     memset(&attr, 0, sizeof(attr)); |  | 
| 764     int result = pthread_mutexattr_init(&attr); |  | 
| 765     ASSERT(result == 0); |  | 
| 766     result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); |  | 
| 767     ASSERT(result == 0); |  | 
| 768     result = pthread_mutex_init(&mutex_, &attr); |  | 
| 769     ASSERT(result == 0); |  | 
| 770     result = pthread_mutexattr_destroy(&attr); |  | 
| 771     ASSERT(result == 0); |  | 
| 772     USE(result); |  | 
| 773   } |  | 
| 774 |  | 
| 775   virtual ~POSIXMutex() { pthread_mutex_destroy(&mutex_); } |  | 
| 776 |  | 
| 777   virtual int Lock() { return pthread_mutex_lock(&mutex_); } |  | 
| 778 |  | 
| 779   virtual int Unlock() { return pthread_mutex_unlock(&mutex_); } |  | 
| 780 |  | 
| 781   virtual bool TryLock() { |  | 
| 782     int result = pthread_mutex_trylock(&mutex_); |  | 
| 783     // Return false if the lock is busy and locking failed. |  | 
| 784     if (result == EBUSY) { |  | 
| 785       return false; |  | 
| 786     } |  | 
| 787     ASSERT(result == 0);  // Verify no other errors. |  | 
| 788     return true; |  | 
| 789   } |  | 
| 790 |  | 
| 791  private: |  | 
| 792   pthread_mutex_t mutex_;   // Pthread mutex for POSIX platforms. |  | 
| 793 }; |  | 
| 794 |  | 
| 795 |  | 
| 796 Mutex* OS::CreateMutex() { |  | 
| 797   return new POSIXMutex(); |  | 
| 798 } |  | 
| 799 |  | 
| 800 |  | 
| 801 // ---------------------------------------------------------------------------- | 759 // ---------------------------------------------------------------------------- | 
| 802 // POSIX socket support. | 760 // POSIX socket support. | 
| 803 // | 761 // | 
| 804 | 762 | 
| 805 class POSIXSocket : public Socket { | 763 class POSIXSocket : public Socket { | 
| 806  public: | 764  public: | 
| 807   explicit POSIXSocket() { | 765   explicit POSIXSocket() { | 
| 808     // Create the socket. | 766     // Create the socket. | 
| 809     socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 767     socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 
| 810     if (IsValid()) { | 768     if (IsValid()) { | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 990   return ntohl(value); | 948   return ntohl(value); | 
| 991 } | 949 } | 
| 992 | 950 | 
| 993 | 951 | 
| 994 Socket* OS::CreateSocket() { | 952 Socket* OS::CreateSocket() { | 
| 995   return new POSIXSocket(); | 953   return new POSIXSocket(); | 
| 996 } | 954 } | 
| 997 | 955 | 
| 998 | 956 | 
| 999 } }  // namespace v8::internal | 957 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|