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

Side by Side Diff: src/platform-macos.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
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 return pthread_getspecific(pthread_key); 645 return pthread_getspecific(pthread_key);
646 } 646 }
647 647
648 648
649 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 649 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
650 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); 650 pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
651 pthread_setspecific(pthread_key, value); 651 pthread_setspecific(pthread_key, value);
652 } 652 }
653 653
654 654
655 void Thread::YieldCPU() {
656 sched_yield();
657 }
658
659
660 class MacOSMutex : public Mutex {
661 public:
662 MacOSMutex() {
663 pthread_mutexattr_t attr;
664 pthread_mutexattr_init(&attr);
665 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
666 pthread_mutex_init(&mutex_, &attr);
Dmitry Lomov (no reviews) 2013/07/11 10:52:16 Hmm MacOS mutex did not have pthread_mutexattr_des
Benedikt Meurer 2013/07/11 10:58:45 Yeah, it's currently a no-op on OS X, but that mig
667 }
668
669 virtual ~MacOSMutex() { pthread_mutex_destroy(&mutex_); }
670
671 virtual int Lock() { return pthread_mutex_lock(&mutex_); }
672 virtual int Unlock() { return pthread_mutex_unlock(&mutex_); }
673
674 virtual bool TryLock() {
675 int result = pthread_mutex_trylock(&mutex_);
676 // Return false if the lock is busy and locking failed.
677 if (result == EBUSY) {
678 return false;
679 }
680 ASSERT(result == 0); // Verify no other errors.
681 return true;
682 }
683
684 private:
685 pthread_mutex_t mutex_;
686 };
687
688
689 Mutex* OS::CreateMutex() {
690 return new MacOSMutex();
691 }
692
693
694 class MacOSSemaphore : public Semaphore { 655 class MacOSSemaphore : public Semaphore {
695 public: 656 public:
696 explicit MacOSSemaphore(int count) { 657 explicit MacOSSemaphore(int count) {
697 int r; 658 int r;
698 r = semaphore_create(mach_task_self(), 659 r = semaphore_create(mach_task_self(),
699 &semaphore_, 660 &semaphore_,
700 SYNC_POLICY_FIFO, 661 SYNC_POLICY_FIFO,
701 count); 662 count);
702 ASSERT(r == KERN_SUCCESS); 663 ASSERT(r == KERN_SUCCESS);
703 } 664 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 limit_mutex = CreateMutex(); 706 limit_mutex = CreateMutex();
746 } 707 }
747 708
748 709
749 void OS::TearDown() { 710 void OS::TearDown() {
750 delete limit_mutex; 711 delete limit_mutex;
751 } 712 }
752 713
753 714
754 } } // namespace v8::internal 715 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698