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

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

Issue 6816038: Do not rely on uniquiness of pthread_t Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Win32 build fix Created 9 years, 8 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-nullos.cc ('k') | src/platform-solaris.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 352 }
353 353
354 354
355 bool VirtualMemory::Uncommit(void* address, size_t size) { 355 bool VirtualMemory::Uncommit(void* address, size_t size) {
356 return mmap(address, size, PROT_NONE, 356 return mmap(address, size, PROT_NONE,
357 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, 357 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
358 kMmapFd, kMmapFdOffset) != MAP_FAILED; 358 kMmapFd, kMmapFdOffset) != MAP_FAILED;
359 } 359 }
360 360
361 361
362 class ThreadHandle::PlatformData : public Malloced { 362 class Thread::PlatformData : public Malloced {
363 public: 363 public:
364 explicit PlatformData(ThreadHandle::Kind kind) { 364 PlatformData() : thread_(kNoThread) {}
365 Initialize(kind);
366 }
367 365
368 void Initialize(ThreadHandle::Kind kind) {
369 switch (kind) {
370 case ThreadHandle::SELF: thread_ = pthread_self(); break;
371 case ThreadHandle::INVALID: thread_ = kNoThread; break;
372 }
373 }
374 pthread_t thread_; // Thread handle for pthread. 366 pthread_t thread_; // Thread handle for pthread.
375 }; 367 };
376 368
377 369
378 ThreadHandle::ThreadHandle(Kind kind) {
379 data_ = new PlatformData(kind);
380 }
381
382
383 void ThreadHandle::Initialize(ThreadHandle::Kind kind) {
384 data_->Initialize(kind);
385 }
386
387
388 ThreadHandle::~ThreadHandle() {
389 delete data_;
390 }
391
392
393 bool ThreadHandle::IsSelf() const {
394 return pthread_equal(data_->thread_, pthread_self());
395 }
396
397
398 bool ThreadHandle::IsValid() const {
399 return data_->thread_ != kNoThread;
400 }
401
402
403 Thread::Thread(Isolate* isolate, const Options& options) 370 Thread::Thread(Isolate* isolate, const Options& options)
404 : ThreadHandle(ThreadHandle::INVALID), 371 : data_(new PlatformData()),
405 isolate_(isolate), 372 isolate_(isolate),
406 stack_size_(options.stack_size) { 373 stack_size_(options.stack_size) {
407 set_name(options.name); 374 set_name(options.name);
408 } 375 }
409 376
410 377
411 Thread::Thread(Isolate* isolate, const char* name) 378 Thread::Thread(Isolate* isolate, const char* name)
412 : ThreadHandle(ThreadHandle::INVALID), 379 : data_(new PlatfromData()),
413 isolate_(isolate), 380 isolate_(isolate),
414 stack_size_(0) { 381 stack_size_(0) {
415 set_name(name); 382 set_name(name);
416 } 383 }
417 384
418 385
419 Thread::~Thread() { 386 Thread::~Thread() {
387 delete data_;
420 } 388 }
421 389
422 390
423 static void* ThreadEntry(void* arg) { 391 static void* ThreadEntry(void* arg) {
424 Thread* thread = reinterpret_cast<Thread*>(arg); 392 Thread* thread = reinterpret_cast<Thread*>(arg);
425 // This is also initialized by the first argument to pthread_create() but we 393 // This is also initialized by the first argument to pthread_create() but we
426 // don't know which thread will run first (the original thread or the new 394 // don't know which thread will run first (the original thread or the new
427 // one) so we initialize it here too. 395 // one) so we initialize it here too.
428 thread->thread_handle_data()->thread_ = pthread_self(); 396 thread->data()->thread_ = pthread_self();
429 ASSERT(thread->IsValid()); 397 ASSERT(thread->data()->thread_ != kNoThread);
430 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 398 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
431 thread->Run(); 399 thread->Run();
432 return NULL; 400 return NULL;
433 } 401 }
434 402
435 403
436 void Thread::set_name(const char* name) { 404 void Thread::set_name(const char* name) {
437 strncpy(name_, name, sizeof(name_)); 405 strncpy(name_, name, sizeof(name_));
438 name_[sizeof(name_) - 1] = '\0'; 406 name_[sizeof(name_) - 1] = '\0';
439 } 407 }
440 408
441 409
442 void Thread::Start() { 410 void Thread::Start() {
443 pthread_attr_t* attr_ptr = NULL; 411 pthread_attr_t* attr_ptr = NULL;
444 pthread_attr_t attr; 412 pthread_attr_t attr;
445 if (stack_size_ > 0) { 413 if (stack_size_ > 0) {
446 pthread_attr_init(&attr); 414 pthread_attr_init(&attr);
447 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); 415 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
448 attr_ptr = &attr; 416 attr_ptr = &attr;
449 } 417 }
450 pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this); 418 pthread_create(&data_->thread_, attr_ptr, ThreadEntry, this);
451 ASSERT(IsValid()); 419 ASSERT(IsValid());
452 } 420 }
453 421
454 422
455 void Thread::Join() { 423 void Thread::Join() {
456 pthread_join(thread_handle_data()->thread_, NULL); 424 pthread_join(data_->thread_, NULL);
457 } 425 }
458 426
459 427
460 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { 428 Thread::LocalStorageKey Thread::CreateThreadLocalKey() {
461 pthread_key_t key; 429 pthread_key_t key;
462 int result = pthread_key_create(&key, NULL); 430 int result = pthread_key_create(&key, NULL);
463 USE(result); 431 USE(result);
464 ASSERT(result == 0); 432 ASSERT(result == 0);
465 return static_cast<LocalStorageKey>(key); 433 return static_cast<LocalStorageKey>(key);
466 } 434 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 } 631 }
664 632
665 // This sampler is no longer the active sampler. 633 // This sampler is no longer the active sampler.
666 active_sampler_ = NULL; 634 active_sampler_ = NULL;
667 active_ = false; 635 active_ = false;
668 } 636 }
669 637
670 #endif // ENABLE_LOGGING_AND_PROFILING 638 #endif // ENABLE_LOGGING_AND_PROFILING
671 639
672 } } // namespace v8::internal 640 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-nullos.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698