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

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

Issue 18335008: Cleanup common POSIX functionality. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Mark result as used Created 7 years, 5 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
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 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 return pthread_getspecific(pthread_key); 886 return pthread_getspecific(pthread_key);
887 } 887 }
888 888
889 889
890 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 890 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
891 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); 891 pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
892 pthread_setspecific(pthread_key, value); 892 pthread_setspecific(pthread_key, value);
893 } 893 }
894 894
895 895
896 void Thread::YieldCPU() {
897 sched_yield();
898 }
899
900
901 class LinuxMutex : public Mutex {
902 public:
903 LinuxMutex() {
904 pthread_mutexattr_t attrs;
905 int result = pthread_mutexattr_init(&attrs);
906 ASSERT(result == 0);
907 result = pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE);
908 ASSERT(result == 0);
909 result = pthread_mutex_init(&mutex_, &attrs);
910 ASSERT(result == 0);
911 USE(result);
912 }
913
914 virtual ~LinuxMutex() { pthread_mutex_destroy(&mutex_); }
915
916 virtual int Lock() {
917 int result = pthread_mutex_lock(&mutex_);
918 return result;
919 }
920
921 virtual int Unlock() {
922 int result = pthread_mutex_unlock(&mutex_);
923 return result;
924 }
925
926 virtual bool TryLock() {
927 int result = pthread_mutex_trylock(&mutex_);
928 // Return false if the lock is busy and locking failed.
929 if (result == EBUSY) {
930 return false;
931 }
932 ASSERT(result == 0); // Verify no other errors.
933 return true;
934 }
935
936 private:
937 pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms.
938 };
939
940
941 Mutex* OS::CreateMutex() {
942 return new LinuxMutex();
943 }
944
945
946 class LinuxSemaphore : public Semaphore { 896 class LinuxSemaphore : public Semaphore {
947 public: 897 public:
948 explicit LinuxSemaphore(int count) { sem_init(&sem_, 0, count); } 898 explicit LinuxSemaphore(int count) { sem_init(&sem_, 0, count); }
949 virtual ~LinuxSemaphore() { sem_destroy(&sem_); } 899 virtual ~LinuxSemaphore() { sem_destroy(&sem_); }
950 900
951 virtual void Wait(); 901 virtual void Wait();
952 virtual bool Wait(int timeout); 902 virtual bool Wait(int timeout);
953 virtual void Signal() { sem_post(&sem_); } 903 virtual void Signal() { sem_post(&sem_); }
954 private: 904 private:
955 sem_t sem_; 905 sem_t sem_;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 limit_mutex = CreateMutex(); 970 limit_mutex = CreateMutex();
1021 } 971 }
1022 972
1023 973
1024 void OS::TearDown() { 974 void OS::TearDown() {
1025 delete limit_mutex; 975 delete limit_mutex;
1026 } 976 }
1027 977
1028 978
1029 } } // namespace v8::internal 979 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | src/platform-macos.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698