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

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

Issue 160099: A small cleanup of MacOSMutex constructor (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 11 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 404
405 void Thread::YieldCPU() { 405 void Thread::YieldCPU() {
406 sched_yield(); 406 sched_yield();
407 } 407 }
408 408
409 409
410 class MacOSMutex : public Mutex { 410 class MacOSMutex : public Mutex {
411 public: 411 public:
412 412
413 MacOSMutex() { 413 MacOSMutex() {
414 // For some reason the compiler doesn't allow you to write
415 // "this->mutex_ = PTHREAD_..." directly on mac.
416 pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
417 pthread_mutexattr_t attr; 414 pthread_mutexattr_t attr;
418 pthread_mutexattr_init(&attr); 415 pthread_mutexattr_init(&attr);
419 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 416 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
420 pthread_mutex_init(&m, &attr); 417 pthread_mutex_init(&mutex_, &attr);
421 mutex_ = m;
422 } 418 }
423 419
424 ~MacOSMutex() { pthread_mutex_destroy(&mutex_); } 420 ~MacOSMutex() { pthread_mutex_destroy(&mutex_); }
425 421
426 int Lock() { return pthread_mutex_lock(&mutex_); } 422 int Lock() { return pthread_mutex_lock(&mutex_); }
427 423
428 int Unlock() { return pthread_mutex_unlock(&mutex_); } 424 int Unlock() { return pthread_mutex_unlock(&mutex_); }
429 425
430 private: 426 private:
431 pthread_mutex_t mutex_; 427 pthread_mutex_t mutex_;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 601
606 // Deallocate Mach port for thread. 602 // Deallocate Mach port for thread.
607 if (IsProfiling()) { 603 if (IsProfiling()) {
608 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); 604 mach_port_deallocate(data_->task_self_, data_->profiled_thread_);
609 } 605 }
610 } 606 }
611 607
612 #endif // ENABLE_LOGGING_AND_PROFILING 608 #endif // ENABLE_LOGGING_AND_PROFILING
613 609
614 } } // namespace v8::internal 610 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698