summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-11 00:15:53 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-11 00:15:53 +0000
commit4613b9ca3fef46a1d868dd14b6550ad2d0c59082 (patch)
tree58507020c865cab3178aad0e53cc8e296335556b
parent7a8ac8ccdcb19d5e4e8eee3605a462dbff0c1fe5 (diff)
downloadchromium_src-4613b9ca3fef46a1d868dd14b6550ad2d0c59082.zip
chromium_src-4613b9ca3fef46a1d868dd14b6550ad2d0c59082.tar.gz
chromium_src-4613b9ca3fef46a1d868dd14b6550ad2d0c59082.tar.bz2
mach_port_deallocate() the result of mach_thread_self(), which obtains a port send right.
BUG=105513 TEST=none Review URL: http://codereview.chromium.org/9169016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117127 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/logging.cc21
-rw-r--r--base/threading/platform_thread_posix.cc4
-rw-r--r--base/threading/platform_thread_unittest.cc21
3 files changed, 24 insertions, 22 deletions
diff --git a/base/logging.cc b/base/logging.cc
index 149bdda..1a51312 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -51,6 +51,7 @@ typedef pthread_mutex_t* MutexHandle;
#include "base/eintr_wrapper.h"
#include "base/string_piece.h"
#include "base/synchronization/lock_impl.h"
+#include "base/threading/platform_thread.h"
#include "base/utf_string_conversions.h"
#include "base/vlog.h"
#if defined(OS_POSIX)
@@ -129,22 +130,6 @@ int32 CurrentProcessId() {
#endif
}
-int32 CurrentThreadId() {
-#if defined(OS_WIN)
- return GetCurrentThreadId();
-#elif defined(OS_MACOSX)
- return mach_thread_self();
-#elif defined(OS_LINUX)
- return syscall(__NR_gettid);
-#elif defined(OS_ANDROID)
- return gettid();
-#elif defined(OS_NACL)
- return pthread_self();
-#elif defined(OS_POSIX)
- return reinterpret_cast<int64>(pthread_self());
-#endif
-}
-
uint64 TickCount() {
#if defined(OS_WIN)
return GetTickCount();
@@ -690,7 +675,7 @@ void LogMessage::Init(const char* file, int line) {
if (log_process_id)
stream_ << CurrentProcessId() << ':';
if (log_thread_id)
- stream_ << CurrentThreadId() << ':';
+ stream_ << base::PlatformThread::CurrentId() << ':';
if (log_timestamp) {
time_t t = time(NULL);
struct tm local_time = {0};
diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc
index 0196ff2..7eda4e9 100644
--- a/base/threading/platform_thread_posix.cc
+++ b/base/threading/platform_thread_posix.cc
@@ -133,7 +133,9 @@ PlatformThreadId PlatformThread::CurrentId() {
// Pthreads doesn't have the concept of a thread ID, so we have to reach down
// into the kernel.
#if defined(OS_MACOSX)
- return mach_thread_self();
+ mach_port_t port = mach_thread_self();
+ mach_port_deallocate(mach_task_self(), port);
+ return port;
#elif defined(OS_LINUX)
return syscall(__NR_gettid);
#elif defined(OS_ANDROID)
diff --git a/base/threading/platform_thread_unittest.cc b/base/threading/platform_thread_unittest.cc
index 6bff1d4..e37709a 100644
--- a/base/threading/platform_thread_unittest.cc
+++ b/base/threading/platform_thread_unittest.cc
@@ -1,7 +1,8 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/compiler_specific.h"
#include "base/threading/platform_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,7 +15,7 @@ class TrivialThread : public PlatformThread::Delegate {
public:
TrivialThread() : did_run_(false) {}
- virtual void ThreadMain() {
+ virtual void ThreadMain() OVERRIDE {
did_run_ = true;
}
@@ -56,11 +57,14 @@ class FunctionTestThread : public TrivialThread {
public:
FunctionTestThread() : thread_id_(0) {}
- virtual void ThreadMain() {
+ virtual void ThreadMain() OVERRIDE {
thread_id_ = PlatformThread::CurrentId();
PlatformThread::YieldCurrentThread();
PlatformThread::Sleep(TimeDelta::FromMilliseconds(50));
+ // Make sure that the thread ID is the same across calls.
+ EXPECT_EQ(thread_id_, PlatformThread::CurrentId());
+
TrivialThread::ThreadMain();
}
@@ -83,6 +87,9 @@ TEST(PlatformThreadTest, Function) {
PlatformThread::Join(handle);
ASSERT_TRUE(thread.did_run());
EXPECT_NE(thread.thread_id(), main_thread_id);
+
+ // Make sure that the thread ID is the same across calls.
+ EXPECT_EQ(main_thread_id, PlatformThread::CurrentId());
}
TEST(PlatformThreadTest, FunctionTimesTen) {
@@ -100,7 +107,15 @@ TEST(PlatformThreadTest, FunctionTimesTen) {
for (size_t n = 0; n < arraysize(thread); n++) {
ASSERT_TRUE(thread[n].did_run());
EXPECT_NE(thread[n].thread_id(), main_thread_id);
+
+ // Make sure no two threads get the same ID.
+ for (size_t i = 0; i < n; ++i) {
+ EXPECT_NE(thread[i].thread_id(), thread[n].thread_id());
+ }
}
+
+ // Make sure that the thread ID is the same across calls.
+ EXPECT_EQ(main_thread_id, PlatformThread::CurrentId());
}
} // namespace base