Merge "Move gettid() into libcutils."
This commit is contained in:
commit
9f8093f888
4 changed files with 38 additions and 26 deletions
|
|
@ -44,6 +44,7 @@ LOCAL_SRC_FILES := $(libbase_src_files)
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||||
LOCAL_CPPFLAGS := $(libbase_cppflags)
|
LOCAL_CPPFLAGS := $(libbase_cppflags)
|
||||||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
||||||
|
LOCAL_STATIC_LIBRARIES := libcutils
|
||||||
LOCAL_MULTILIB := both
|
LOCAL_MULTILIB := both
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
||||||
|
|
@ -53,6 +54,7 @@ LOCAL_CLANG := true
|
||||||
LOCAL_WHOLE_STATIC_LIBRARIES := libbase
|
LOCAL_WHOLE_STATIC_LIBRARIES := libbase
|
||||||
LOCAL_SHARED_LIBRARIES := liblog
|
LOCAL_SHARED_LIBRARIES := liblog
|
||||||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
||||||
|
LOCAL_SHARED_LIBRARIES := libcutils
|
||||||
LOCAL_MULTILIB := both
|
LOCAL_MULTILIB := both
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
|
@ -64,6 +66,7 @@ LOCAL_SRC_FILES := $(libbase_src_files)
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||||
LOCAL_CPPFLAGS := $(libbase_cppflags)
|
LOCAL_CPPFLAGS := $(libbase_cppflags)
|
||||||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
||||||
|
LOCAL_STATIC_LIBRARIES := libcutils
|
||||||
LOCAL_MULTILIB := both
|
LOCAL_MULTILIB := both
|
||||||
include $(BUILD_HOST_STATIC_LIBRARY)
|
include $(BUILD_HOST_STATIC_LIBRARY)
|
||||||
|
|
||||||
|
|
@ -72,6 +75,7 @@ LOCAL_MODULE := libbase
|
||||||
LOCAL_WHOLE_STATIC_LIBRARIES := libbase
|
LOCAL_WHOLE_STATIC_LIBRARIES := libbase
|
||||||
LOCAL_SHARED_LIBRARIES := liblog
|
LOCAL_SHARED_LIBRARIES := liblog
|
||||||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
|
||||||
|
LOCAL_STATIC_LIBRARIES := libcutils
|
||||||
LOCAL_MULTILIB := both
|
LOCAL_MULTILIB := both
|
||||||
include $(BUILD_HOST_SHARED_LIBRARY)
|
include $(BUILD_HOST_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/strings.h"
|
#include "base/strings.h"
|
||||||
|
#include "cutils/threads.h"
|
||||||
|
|
||||||
// Headers for LogMessage::LogLine.
|
// Headers for LogMessage::LogLine.
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
|
@ -33,15 +34,6 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For GetTid.
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#elif !defined(__BIONIC__)
|
|
||||||
#include <syscall.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace base {
|
namespace base {
|
||||||
|
|
||||||
|
|
@ -52,19 +44,6 @@ static std::unique_ptr<std::string> gCmdLine;
|
||||||
static std::unique_ptr<std::string> gProgramInvocationName;
|
static std::unique_ptr<std::string> gProgramInvocationName;
|
||||||
static std::unique_ptr<std::string> gProgramInvocationShortName;
|
static std::unique_ptr<std::string> gProgramInvocationShortName;
|
||||||
|
|
||||||
#ifndef __ANDROID__
|
|
||||||
static pid_t GetTid() {
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
uint64_t owner;
|
|
||||||
// Requires Mac OS 10.6
|
|
||||||
CHECK_PTHREAD_CALL(pthread_threadid_np, (NULL, &owner), __FUNCTION__);
|
|
||||||
return owner;
|
|
||||||
#else
|
|
||||||
return syscall(__NR_gettid);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif // __ANDROID__
|
|
||||||
|
|
||||||
const char* GetCmdLine() {
|
const char* GetCmdLine() {
|
||||||
return (gCmdLine.get() != nullptr) ? gCmdLine->c_str() : nullptr;
|
return (gCmdLine.get() != nullptr) ? gCmdLine->c_str() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -261,7 +240,7 @@ void LogMessage::LogLine(const char* file, unsigned int line,
|
||||||
CHECK_EQ(strlen(log_characters), FATAL + 1U);
|
CHECK_EQ(strlen(log_characters), FATAL + 1U);
|
||||||
char severity = log_characters[log_severity];
|
char severity = log_characters[log_severity];
|
||||||
fprintf(stderr, "%s %c %5d %5d %s:%u] %s\n", ProgramInvocationShortName(),
|
fprintf(stderr, "%s %c %5d %5d %s:%u] %s\n", ProgramInvocationShortName(),
|
||||||
severity, getpid(), GetTid(), file, line, message);
|
severity, getpid(), gettid(), file, line, message);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,10 @@ typedef struct {
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
int has_tls;
|
int has_tls;
|
||||||
pthread_key_t tls;
|
pthread_key_t tls;
|
||||||
|
|
||||||
} thread_store_t;
|
} thread_store_t;
|
||||||
|
|
||||||
|
extern pid_t gettid();
|
||||||
|
|
||||||
#define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 }
|
#define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 }
|
||||||
|
|
||||||
#else // !defined(_WIN32)
|
#else // !defined(_WIN32)
|
||||||
|
|
@ -51,7 +52,6 @@ typedef struct {
|
||||||
int has_tls;
|
int has_tls;
|
||||||
DWORD tls;
|
DWORD tls;
|
||||||
CRITICAL_SECTION lock;
|
CRITICAL_SECTION lock;
|
||||||
|
|
||||||
} thread_store_t;
|
} thread_store_t;
|
||||||
|
|
||||||
#define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} }
|
#define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} }
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,23 @@
|
||||||
** limitations under the License.
|
** limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cutils/threads.h>
|
#include "cutils/threads.h"
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
|
|
||||||
|
// For gettid.
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include "base/logging.h"
|
||||||
|
#elif defined(__linux__) && !defined(__ANDROID__)
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include <Windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void* thread_store_get( thread_store_t* store )
|
void* thread_store_get( thread_store_t* store )
|
||||||
{
|
{
|
||||||
if (!store->has_tls)
|
if (!store->has_tls)
|
||||||
|
|
@ -42,6 +56,21 @@ extern void thread_store_set( thread_store_t* store,
|
||||||
pthread_setspecific( store->tls, value );
|
pthread_setspecific( store->tls, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No definition needed for Android because we'll just pick up bionic's copy.
|
||||||
|
#ifndef __ANDROID__
|
||||||
|
pid_t gettid() {
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
uint64_t owner;
|
||||||
|
CHECK_PTHREAD_CALL(pthread_threadid_np, (NULL, &owner), __FUNCTION__);
|
||||||
|
return owner;
|
||||||
|
#elif defined(__linux__)
|
||||||
|
return syscall(__NR_gettid);
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
return (pid_t)GetCurrentThreadId();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif // __ANDROID__
|
||||||
|
|
||||||
#else /* !defined(_WIN32) */
|
#else /* !defined(_WIN32) */
|
||||||
void* thread_store_get( thread_store_t* store )
|
void* thread_store_get( thread_store_t* store )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue