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

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

Issue 19490010: Avoid duplication of OS::Thread methods for every POSIX platform. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Tweaks 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-posix.cc ('k') | 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 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return x < 0; 74 return x < 0;
75 } 75 }
76 } 76 }
77 } // namespace std 77 } // namespace std
78 #endif // signbit 78 #endif // signbit
79 79
80 namespace v8 { 80 namespace v8 {
81 namespace internal { 81 namespace internal {
82 82
83 83
84 // 0 is never a valid thread id on Solaris since the main thread is 1 and
85 // subsequent have their ids incremented from there
86 static const pthread_t kNoThread = (pthread_t) 0;
87
88
89 double ceiling(double x) { 84 double ceiling(double x) {
90 return ceil(x); 85 return ceil(x);
91 } 86 }
92 87
93 88
94 static Mutex* limit_mutex = NULL; 89 static Mutex* limit_mutex = NULL;
95 90
96 91
97 uint64_t OS::CpuFeaturesImpliedByPlatform() { 92 uint64_t OS::CpuFeaturesImpliedByPlatform() {
98 return 0; // Solaris runs on a lot of things. 93 return 0; // Solaris runs on a lot of things.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 return munmap(base, size) == 0; 402 return munmap(base, size) == 0;
408 } 403 }
409 404
410 405
411 bool VirtualMemory::HasLazyCommits() { 406 bool VirtualMemory::HasLazyCommits() {
412 // TODO(alph): implement for the platform. 407 // TODO(alph): implement for the platform.
413 return false; 408 return false;
414 } 409 }
415 410
416 411
417 class Thread::PlatformData : public Malloced {
418 public:
419 PlatformData() : thread_(kNoThread) { }
420
421 pthread_t thread_; // Thread handle for pthread.
422 };
423
424
425 Thread::Thread(const Options& options)
426 : data_(new PlatformData()),
427 stack_size_(options.stack_size()),
428 start_semaphore_(NULL) {
429 set_name(options.name());
430 }
431
432
433 Thread::~Thread() {
434 delete data_;
435 }
436
437
438 static void* ThreadEntry(void* arg) {
439 Thread* thread = reinterpret_cast<Thread*>(arg);
440 // This is also initialized by the first argument to pthread_create() but we
441 // don't know which thread will run first (the original thread or the new
442 // one) so we initialize it here too.
443 thread->data()->thread_ = pthread_self();
444 ASSERT(thread->data()->thread_ != kNoThread);
445 thread->NotifyStartedAndRun();
446 return NULL;
447 }
448
449
450 void Thread::set_name(const char* name) {
451 strncpy(name_, name, sizeof(name_));
452 name_[sizeof(name_) - 1] = '\0';
453 }
454
455
456 void Thread::Start() {
457 pthread_attr_t attr;
458 if (stack_size_ > 0) {
459 pthread_attr_init(&attr);
460 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
461 }
462 pthread_create(&data_->thread_, NULL, ThreadEntry, this);
463 ASSERT(data_->thread_ != kNoThread);
464 }
465
466
467 void Thread::Join() {
468 pthread_join(data_->thread_, NULL);
469 }
470
471
472 Thread::LocalStorageKey Thread::CreateThreadLocalKey() {
473 pthread_key_t key;
474 int result = pthread_key_create(&key, NULL);
475 USE(result);
476 ASSERT(result == 0);
477 return static_cast<LocalStorageKey>(key);
478 }
479
480
481 void Thread::DeleteThreadLocalKey(LocalStorageKey key) {
482 pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
483 int result = pthread_key_delete(pthread_key);
484 USE(result);
485 ASSERT(result == 0);
486 }
487
488
489 void* Thread::GetThreadLocal(LocalStorageKey key) {
490 pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
491 return pthread_getspecific(pthread_key);
492 }
493
494
495 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
496 pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
497 pthread_setspecific(pthread_key, value);
498 }
499
500
501 class SolarisSemaphore : public Semaphore { 412 class SolarisSemaphore : public Semaphore {
502 public: 413 public:
503 explicit SolarisSemaphore(int count) { sem_init(&sem_, 0, count); } 414 explicit SolarisSemaphore(int count) { sem_init(&sem_, 0, count); }
504 virtual ~SolarisSemaphore() { sem_destroy(&sem_); } 415 virtual ~SolarisSemaphore() { sem_destroy(&sem_); }
505 416
506 virtual void Wait(); 417 virtual void Wait();
507 virtual bool Wait(int timeout); 418 virtual bool Wait(int timeout);
508 virtual void Signal() { sem_post(&sem_); } 419 virtual void Signal() { sem_post(&sem_); }
509 private: 420 private:
510 sem_t sem_; 421 sem_t sem_;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 limit_mutex = CreateMutex(); 498 limit_mutex = CreateMutex();
588 } 499 }
589 500
590 501
591 void OS::TearDown() { 502 void OS::TearDown() {
592 delete limit_mutex; 503 delete limit_mutex;
593 } 504 }
594 505
595 506
596 } } // namespace v8::internal 507 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698