Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bthread/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ int first_sys_pthread_mutex_unlock(pthread_mutex_t* mutex) {
pthread_once(&init_sys_mutex_lock_once, init_sys_mutex_lock);
return sys_pthread_mutex_unlock(mutex);
}
#endif
#endif // NO_PTHREAD_MUTEX_HOOK

template <typename Mutex>
inline uint64_t hash_mutex_ptr(const Mutex* m) {
Expand Down Expand Up @@ -988,7 +988,7 @@ BUTIL_FORCE_INLINE int pthread_mutex_timedlock_impl(pthread_mutex_t* mutex,
BUTIL_FORCE_INLINE int pthread_mutex_unlock_impl(pthread_mutex_t* mutex) {
return internal::pthread_mutex_unlock_impl(mutex);
}
#endif
#endif // NO_PTHREAD_MUTEX_HOOK

// Implement bthread_mutex_t related functions
struct MutexInternal {
Expand Down
18 changes: 15 additions & 3 deletions src/butil/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ bool show_error_dialogs = false;
// the debug message dialog and process termination.
LogAssertHandler log_assert_handler = NULL;

BAIDU_VOLATILE_THREAD_LOCAL(int32_t, tls_log_pid, 0);
BAIDU_VOLATILE_THREAD_LOCAL(butil::PlatformThreadId, tls_log_tid, 0);

// Helper functions to wrap platform differences.

int32_t CurrentProcessId() {
Expand Down Expand Up @@ -865,10 +868,19 @@ void PrintLogPrefix(std::ostream& os, int severity,
os << '.' << std::setw(6) << tv.tv_usec;
#endif
if (FLAGS_log_pid) {
os << ' ' << std::setfill(' ') << std::setw(5) << CurrentProcessId();
int32_t pid = BAIDU_GET_VOLATILE_THREAD_LOCAL(tls_log_pid);
if (pid == 0) {
pid = CurrentProcessId();
BAIDU_SET_VOLATILE_THREAD_LOCAL(tls_log_pid, pid);
}
os << ' ' << std::setfill(' ') << std::setw(5) << pid;
}
butil::PlatformThreadId tid = BAIDU_GET_VOLATILE_THREAD_LOCAL(tls_log_tid);
if (tid == 0) {
tid = butil::PlatformThread::CurrentId();
BAIDU_SET_VOLATILE_THREAD_LOCAL(tls_log_tid, tid);
}
os << ' ' << std::setfill(' ') << std::setw(5)
<< butil::PlatformThread::CurrentId() << std::setfill('0');
os << ' ' << std::setfill(' ') << std::setw(5) << tid << std::setfill('0');
if (FLAGS_log_bid && bthread_self) {
os << ' ' << std::setfill(' ') << std::setw(5) << bthread_self();
}
Expand Down
Loading