Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: src/platform-posix.cc

Issue 23625003: Cleanup Mutex and related classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 732
733 733
734 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 734 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
735 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 735 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
736 int result = pthread_setspecific(pthread_key, value); 736 int result = pthread_setspecific(pthread_key, value);
737 ASSERT_EQ(0, result); 737 ASSERT_EQ(0, result);
738 USE(result); 738 USE(result);
739 } 739 }
740 740
741 741
742 class POSIXMutex : public Mutex {
743 public:
744 POSIXMutex() {
745 pthread_mutexattr_t attr;
746 memset(&attr, 0, sizeof(attr));
747 int result = pthread_mutexattr_init(&attr);
748 ASSERT(result == 0);
749 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
750 ASSERT(result == 0);
751 result = pthread_mutex_init(&mutex_, &attr);
752 ASSERT(result == 0);
753 result = pthread_mutexattr_destroy(&attr);
754 ASSERT(result == 0);
755 USE(result);
756 }
757
758 virtual ~POSIXMutex() { pthread_mutex_destroy(&mutex_); }
759
760 virtual int Lock() { return pthread_mutex_lock(&mutex_); }
761
762 virtual int Unlock() { return pthread_mutex_unlock(&mutex_); }
763
764 virtual bool TryLock() {
765 int result = pthread_mutex_trylock(&mutex_);
766 // Return false if the lock is busy and locking failed.
767 if (result == EBUSY) {
768 return false;
769 }
770 ASSERT(result == 0); // Verify no other errors.
771 return true;
772 }
773
774 private:
775 pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms.
776 };
777
778
779 Mutex* OS::CreateMutex() {
780 return new POSIXMutex();
781 }
782
783
784 // ---------------------------------------------------------------------------- 742 // ----------------------------------------------------------------------------
785 // POSIX socket support. 743 // POSIX socket support.
786 // 744 //
787 745
788 class POSIXSocket : public Socket { 746 class POSIXSocket : public Socket {
789 public: 747 public:
790 explicit POSIXSocket() { 748 explicit POSIXSocket() {
791 // Create the socket. 749 // Create the socket.
792 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 750 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
793 if (IsValid()) { 751 if (IsValid()) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 return ntohl(value); 931 return ntohl(value);
974 } 932 }
975 933
976 934
977 Socket* OS::CreateSocket() { 935 Socket* OS::CreateSocket() {
978 return new POSIXSocket(); 936 return new POSIXSocket();
979 } 937 }
980 938
981 939
982 } } // namespace v8::internal 940 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698