Switch thread_local to use ThreadPlatformStorage in Android

It might not be good to switch thread_local to use ThreadPlatformStorage
on all platforms, in order to pass all tests in Linux, the number of TLS
slot has be 1024, it means 4k memory will be temporarily increased in stack,
and then move to heap for every thread which use the TLS.

Android only needs 256 slot which is much smaller than Linux's usage, and
TLS slot is currently only running out on Android's tests.

So this patch is only for Android platform.

BUG=264406

Review URL: https://codereview.chromium.org/189263003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269854 0039d316-1c4b-4281-b951-d872f2087c98
parent 31acf3ef
......@@ -610,6 +610,7 @@
'threading/thread_id_name_manager.cc',
'threading/thread_id_name_manager.h',
'threading/thread_local.h',
'threading/thread_local_android.cc',
'threading/thread_local_posix.cc',
'threading/thread_local_storage.cc',
'threading/thread_local_storage.h',
......
......@@ -26,6 +26,9 @@
// you must of course properly deal with safety and race conditions. This
// means a function-level static initializer is generally inappropiate.
//
// In Android, the system TLS is limited, the implementation is backed with
// ThreadLocalStorage.
//
// Example usage:
// // My class is logically attached to a single thread. We cache a pointer
// // on the thread it was created on, so we can implement current().
......@@ -50,6 +53,7 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/threading/thread_local_storage.h"
#if defined(OS_POSIX)
#include <pthread.h>
......@@ -62,6 +66,8 @@ namespace internal {
struct BASE_EXPORT ThreadLocalPlatform {
#if defined(OS_WIN)
typedef unsigned long SlotType;
#elif defined(OS_ANDROID)
typedef ThreadLocalStorage::StaticSlot SlotType;
#elif defined(OS_POSIX)
typedef pthread_key_t SlotType;
#endif
......
// Copyright 2014 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/threading/thread_local.h"
#include "base/logging.h"
namespace base {
namespace internal {
// static
void ThreadLocalPlatform::AllocateSlot(SlotType* slot) {
bool succeed = slot->Initialize(NULL);
CHECK(succeed);
}
// static
void ThreadLocalPlatform::FreeSlot(SlotType slot) {
slot.Free();
}
// static
void* ThreadLocalPlatform::GetValueFromSlot(SlotType slot) {
return slot.Get();
}
// static
void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) {
slot.Set(value);
}
} // namespace internal
} // namespace base
......@@ -8,6 +8,8 @@
#include "base/logging.h"
#if !defined(OS_ANDROID)
namespace base {
namespace internal {
......@@ -36,3 +38,5 @@ void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) {
} // namespace internal
} // namespace base
#endif // !defined(OS_ANDROID)
......@@ -31,7 +31,7 @@ base::subtle::AtomicWord g_native_tls_key =
base::subtle::Atomic32 g_last_used_tls_key = 0;
// The maximum number of 'slots' in our thread local storage stack.
const int kThreadLocalStorageSize = 64;
const int kThreadLocalStorageSize = 256;
// The maximum number of times to try to clear slots by calling destructors.
// Use pthread naming convention for clarity.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment