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

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

Issue 23748003: Cleanup Semaphore class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Build fix for Mac OS X. 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-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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 bool VirtualMemory::ReleaseRegion(void* address, size_t size) { 385 bool VirtualMemory::ReleaseRegion(void* address, size_t size) {
386 return munmap(address, size) == 0; 386 return munmap(address, size) == 0;
387 } 387 }
388 388
389 389
390 bool VirtualMemory::HasLazyCommits() { 390 bool VirtualMemory::HasLazyCommits() {
391 return false; 391 return false;
392 } 392 }
393 393
394 394
395 class MacOSSemaphore : public Semaphore {
396 public:
397 explicit MacOSSemaphore(int count) {
398 int r;
399 r = semaphore_create(mach_task_self(),
400 &semaphore_,
401 SYNC_POLICY_FIFO,
402 count);
403 ASSERT(r == KERN_SUCCESS);
404 }
405
406 ~MacOSSemaphore() {
407 int r;
408 r = semaphore_destroy(mach_task_self(), semaphore_);
409 ASSERT(r == KERN_SUCCESS);
410 }
411
412 void Wait() {
413 int r;
414 do {
415 r = semaphore_wait(semaphore_);
416 ASSERT(r == KERN_SUCCESS || r == KERN_ABORTED);
417 } while (r == KERN_ABORTED);
418 }
419
420 bool Wait(int timeout);
421
422 void Signal() { semaphore_signal(semaphore_); }
423
424 private:
425 semaphore_t semaphore_;
426 };
427
428
429 bool MacOSSemaphore::Wait(int timeout) {
430 mach_timespec_t ts;
431 ts.tv_sec = timeout / 1000000;
432 ts.tv_nsec = (timeout % 1000000) * 1000;
433 return semaphore_timedwait(semaphore_, ts) != KERN_OPERATION_TIMED_OUT;
434 }
435
436
437 Semaphore* OS::CreateSemaphore(int count) {
438 return new MacOSSemaphore(count);
439 }
440
441
442 void OS::SetUp() { 395 void OS::SetUp() {
443 // Seed the random number generator. We preserve microsecond resolution. 396 // Seed the random number generator. We preserve microsecond resolution.
444 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()) ^ (getpid() << 16); 397 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()) ^ (getpid() << 16);
445 srandom(static_cast<unsigned int>(seed)); 398 srandom(static_cast<unsigned int>(seed));
446 limit_mutex = new Mutex(); 399 limit_mutex = new Mutex();
447 } 400 }
448 401
449 402
450 void OS::TearDown() { 403 void OS::TearDown() {
451 delete limit_mutex; 404 delete limit_mutex;
452 } 405 }
453 406
454 407
455 } } // namespace v8::internal 408 } } // 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