summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-13 23:20:03 +0000
committerpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-13 23:20:03 +0000
commite5acbcdda213e7d47c7b6cfa5778bb14b4ef20e3 (patch)
treef358ffbdc3dab9c3d2de2ce057be3343f6c0c385
parent1132e5bc06864ff57902a280f528f01bb00c2043 (diff)
downloadchromium_src-e5acbcdda213e7d47c7b6cfa5778bb14b4ef20e3.zip
chromium_src-e5acbcdda213e7d47c7b6cfa5778bb14b4ef20e3.tar.gz
chromium_src-e5acbcdda213e7d47c7b6cfa5778bb14b4ef20e3.tar.bz2
Fix for mac and linux. Fix gcc warning about class with virtual functions and no virtual dtor.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@842 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/platform_thread.cc17
-rw-r--r--base/platform_thread.h3
-rw-r--r--base/stats_table.cc26
3 files changed, 41 insertions, 5 deletions
diff --git a/base/platform_thread.cc b/base/platform_thread.cc
index 6668f9c..8382541 100644
--- a/base/platform_thread.cc
+++ b/base/platform_thread.cc
@@ -34,6 +34,12 @@
#include <sched.h>
#endif
+#if defined(OS_MACOSX)
+#include <mach/mach.h>
+#elif defined(OS_LINUX)
+#include <sys/types.h>
+#endif
+
// static
PlatformThread PlatformThread::Current() {
PlatformThread thread;
@@ -73,6 +79,17 @@ void PlatformThread::Sleep(int duration_ms) {
#endif
}
+// static
+int PlatformThread::CurrentId() {
+#if defined(OS_WIN)
+ return GetCurrentThreadId();
+#elif defined(OS_MACOSX)
+ return mach_thread_self();
+#elif defined(OS_LINUX)
+ return gettid();
+#endif
+}
+
bool PlatformThread::operator==(const PlatformThread& other_thread) {
#if defined(OS_WIN)
return thread_ == other_thread.thread_;
diff --git a/base/platform_thread.h b/base/platform_thread.h
index 82f3362..bb75efe 100644
--- a/base/platform_thread.h
+++ b/base/platform_thread.h
@@ -48,6 +48,9 @@ class PlatformThread {
public:
// Gets the current thread.
static PlatformThread Current();
+
+ // Gets the current thread id
+ static int CurrentId();
// Yield the current thread so another thread can be scheduled.
static void YieldCurrentThread();
diff --git a/base/stats_table.cc b/base/stats_table.cc
index 8213c34..23c736a 100644
--- a/base/stats_table.cc
+++ b/base/stats_table.cc
@@ -29,8 +29,14 @@
#include "base/stats_table.h"
+#include "base/string_util.h"
#include "base/logging.h"
#include "base/thread_local_storage.h"
+#include "base/platform_thread.h"
+
+#if defined(OS_POSIX)
+#include "errno.h"
+#endif
// The StatsTable uses a shared memory segment that is laid out as follows
//
@@ -263,8 +269,13 @@ StatsTable::StatsTable(const std::wstring& name, int max_threads,
if (shared_memory_.Map(table_size))
impl_ = new StatsTablePrivate(shared_memory_.memory(), table_size,
max_threads, max_counters);
+#if defined(OS_WIN)
if (!impl_)
LOG(ERROR) << "StatsTable did not initialize:" << GetLastError();
+#elif defined(OS_POSIX)
+ if (!impl_)
+ LOG(ERROR) << "StatsTable did not initialize:" << strerror(errno);
+#endif
}
StatsTable::~StatsTable() {
@@ -303,10 +314,15 @@ int StatsTable::RegisterThread(const std::wstring& name) {
std::wstring thread_name = name;
if (name.empty())
thread_name = kUnknownName;
- wcsncpy_s(impl_->thread_name(slot), kMaxThreadNameLength,
- thread_name.c_str(), _TRUNCATE);
- *(impl_->thread_tid(slot)) = GetCurrentThreadId();
+ base::wcslcpy(impl_->thread_name(slot), thread_name.c_str(),
+ kMaxThreadNameLength);
+ *(impl_->thread_tid(slot)) = PlatformThread::CurrentId();
+ // TODO(pinkerton): these should go into process_utils when it's ported
+#if defined(OS_WIN)
*(impl_->thread_pid(slot)) = GetCurrentProcessId();
+#elif defined(OS_POSIX)
+ *(impl_->thread_pid(slot)) = getpid();
+#endif
}
// Set our thread local storage.
@@ -452,8 +468,8 @@ int StatsTable::AddCounter(const std::wstring& name) {
std::wstring counter_name = name;
if (name.empty())
counter_name = kUnknownName;
- wcsncpy_s(impl_->counter_name(counter_id), kMaxCounterNameLength,
- counter_name.c_str(), _TRUNCATE);
+ base::wcslcpy(impl_->counter_name(counter_id), counter_name.c_str(),
+ kMaxCounterNameLength);
}
// now add to our in-memory cache