Skip to content

Commit

Permalink
Merge pull request #156 from Chilledheart/print_pthread_info
Browse files Browse the repository at this point in the history
Print pthread_t in a more safe way
  • Loading branch information
igorcanadi committed May 21, 2014
2 parents 62d2b92 + 81b498b commit 220132b
Showing 1 changed file with 12 additions and 2 deletions.
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");
}

#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

0 comments on commit 220132b

Please sign in to comment.