Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print pthread_t in a more safe way #156

Merged
merged 1 commit into from May 21, 2014
Merged
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
14 changes: 12 additions & 2 deletions util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ static Status IOError(const std::string& context, int err_number) {
return Status::IOError(context, strerror(err_number));
}

// TODO(sdong): temp logging. Need to help debugging. Remove it when
// the feature is proved to be stable.
inline void PrintThreadInfo(size_t thread_id, pthread_t id) {
unsigned char* ptc = (unsigned char*)(void*)(&id);
fprintf(stdout, "Bg thread %zu terminates 0x", thread_id);
for (size_t i = 0; i < sizeof(id); i++) {
fprintf(stdout, "%02x", (unsigned)(ptc[i]));
}
fprintf(stdout, "\n");
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you wrap this in an anonymous namespace?

Also, RocksDB's style function name: PrintThreadInfo()

#ifdef NDEBUG
// empty in release build
#define TEST_KILL_RANDOM(rocksdb_kill_odds)
Expand Down Expand Up @@ -1514,8 +1525,7 @@ class PosixEnv : public Env {
PthreadCall("unlock", pthread_mutex_unlock(&mu_));
// TODO(sdong): temp logging. Need to help debugging. Remove it when
// the feature is proved to be stable.
fprintf(stdout, "Bg thread %zu terminates %llx\n", thread_id,
static_cast<long long unsigned int>(terminating_thread));
PrintThreadInfo(thread_id, terminating_thread);
break;
}
void (*function)(void*) = queue_.front().function;
Expand Down