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

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

Issue 20216003: Setting the thread name may fail, so don't assert that the result is 0. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 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 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 set_name(options.name()); 495 set_name(options.name());
496 } 496 }
497 497
498 498
499 Thread::~Thread() { 499 Thread::~Thread() {
500 delete data_; 500 delete data_;
501 } 501 }
502 502
503 503
504 static void SetThreadName(const char* name) { 504 static void SetThreadName(const char* name) {
505 int result = 0;
506 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) 505 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
507 result = pthread_set_name_np(pthread_self(), name); 506 pthread_set_name_np(pthread_self(), name);
508 #elif defined(__NetBSD__) 507 #elif defined(__NetBSD__)
509 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP); 508 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP);
510 result = pthread_setname_np(pthread_self(), "%s", name); 509 pthread_setname_np(pthread_self(), "%s", name);
511 #elif defined(__APPLE__) 510 #elif defined(__APPLE__)
512 // pthread_setname_np is only available in 10.6 or later, so test 511 // pthread_setname_np is only available in 10.6 or later, so test
513 // for it at runtime. 512 // for it at runtime.
514 int (*dynamic_pthread_setname_np)(const char*); 513 int (*dynamic_pthread_setname_np)(const char*);
515 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = 514 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) =
516 dlsym(RTLD_DEFAULT, "pthread_setname_np"); 515 dlsym(RTLD_DEFAULT, "pthread_setname_np");
517 if (dynamic_pthread_setname_np == NULL) 516 if (dynamic_pthread_setname_np == NULL)
518 return; 517 return;
519 518
520 // Mac OS X does not expose the length limit of the name, so hardcode it. 519 // Mac OS X does not expose the length limit of the name, so hardcode it.
521 static const int kMaxNameLength = 63; 520 static const int kMaxNameLength = 63;
522 STATIC_ASSERT(Thread::kMaxThreadNameLength <= kMaxNameLength); 521 STATIC_ASSERT(Thread::kMaxThreadNameLength <= kMaxNameLength);
523 result = dynamic_pthread_setname_np(name); 522 dynamic_pthread_setname_np(name);
524 #elif defined(PR_SET_NAME) 523 #elif defined(PR_SET_NAME)
525 result = prctl(PR_SET_NAME, 524 prctl(PR_SET_NAME,
526 reinterpret_cast<unsigned long>(name), // NOLINT 525 reinterpret_cast<unsigned long>(name), // NOLINT
527 0, 0, 0); 526 0, 0, 0);
528 #endif 527 #endif
529 ASSERT_EQ(0, result);
530 USE(result);
531 } 528 }
532 529
533 530
534 static void* ThreadEntry(void* arg) { 531 static void* ThreadEntry(void* arg) {
535 Thread* thread = reinterpret_cast<Thread*>(arg); 532 Thread* thread = reinterpret_cast<Thread*>(arg);
536 // This is also initialized by the first argument to pthread_create() but we 533 // This is also initialized by the first argument to pthread_create() but we
537 // don't know which thread will run first (the original thread or the new 534 // don't know which thread will run first (the original thread or the new
538 // one) so we initialize it here too. 535 // one) so we initialize it here too.
539 thread->data()->thread_ = pthread_self(); 536 thread->data()->thread_ = pthread_self();
540 SetThreadName(thread->name()); 537 SetThreadName(thread->name());
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 return ntohl(value); 939 return ntohl(value);
943 } 940 }
944 941
945 942
946 Socket* OS::CreateSocket() { 943 Socket* OS::CreateSocket() {
947 return new POSIXSocket(); 944 return new POSIXSocket();
948 } 945 }
949 946
950 947
951 } } // namespace v8::internal 948 } } // 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