Wrap everything with macro

pull/16714/head
Muxi Yan 6 years ago
parent d5d881ae9f
commit 57d1bae72b
  1. 27
      src/core/lib/gpr/sync_posix.cc
  2. 21
      src/core/lib/iomgr/timer_manager.cc

@ -27,14 +27,20 @@
#include <time.h> #include <time.h>
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
// For debug only. Forward statistics to another module. // For debug of the timer manager crash only.
void (*g_grpc_debug_timer_manager_stats)(int64_t timer_manager_init_count, int64_t timer_manager_shutdown_count, int64_t fork_count, int64_t timer_wait_err, int64_t timer_wait_cv) = nullptr; // TODO (mxyan): remove after bug is fixed.
// For debug only. Variables storing the counters being logged. #ifdef GRPC_DEBUG_TIMER_MANAGER
void (*g_grpc_debug_timer_manager_stats)(int64_t timer_manager_init_count,
int64_t timer_manager_shutdown_count,
int64_t fork_count,
int64_t timer_wait_err,
int64_t timer_wait_cv) = nullptr;
int64_t g_timer_manager_init_count = 0; int64_t g_timer_manager_init_count = 0;
int64_t g_timer_manager_shutdown_count = 0; int64_t g_timer_manager_shutdown_count = 0;
int64_t g_fork_count = 0; int64_t g_fork_count = 0;
int64_t g_timer_wait_err = 0; int64_t g_timer_wait_err = 0;
int64_t g_timer_wait_cv = 0; int64_t g_timer_wait_cv = 0;
#endif // GRPC_DEBUG_TIMER_MANAGER
#ifdef GPR_LOW_LEVEL_COUNTERS #ifdef GPR_LOW_LEVEL_COUNTERS
gpr_atm gpr_mu_locks = 0; gpr_atm gpr_mu_locks = 0;
@ -97,18 +103,23 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec;
err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts);
} }
#ifdef GRPC_DEBUG_TIMER_MANAGER
// For debug of the timer manager crash only.
// TODO (mxyan): remove after bug is fixed.
if (!(err == 0 || err == ETIMEDOUT || err == EAGAIN)) { if (!(err == 0 || err == ETIMEDOUT || err == EAGAIN)) {
if (g_grpc_debug_timer_manager_stats) { if (g_grpc_debug_timer_manager_stats) {
g_timer_wait_err = err; g_timer_wait_err = err;
g_timer_wait_cv = (int64_t)cv; g_timer_wait_cv = (int64_t)cv;
g_grpc_debug_timer_manager_stats(g_timer_manager_init_count, g_grpc_debug_timer_manager_stats(
g_timer_manager_shutdown_count, g_timer_manager_init_count, g_timer_manager_shutdown_count,
g_fork_count, g_fork_count, g_timer_wait_err, g_timer_wait_cv);
g_timer_wait_err,
g_timer_wait_cv);
} }
GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN); GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN);
} }
#else
GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN);
#endif
return err == ETIMEDOUT; return err == ETIMEDOUT;
} }

@ -61,14 +61,15 @@ static uint64_t g_timed_waiter_generation;
static void timer_thread(void* completed_thread_ptr); static void timer_thread(void* completed_thread_ptr);
// For debug only. Forward statistics to another module. // For debug of the timer manager crash only.
extern void (*g_grpc_debug_timer_manager_stats)(int64_t timer_manager_init_count, int64_t timer_manager_shutdown_count, int64_t fork_count, int64_t timer_wait_err, int64_t timer_wait_cv); // TODO (mxyan): remove after bug is fixed.
// For debug only. Variables storing the counters being logged. #ifdef GRPC_DEBUG_TIMER_MANAGER
extern int64_t g_timer_manager_init_count; extern int64_t g_timer_manager_init_count;
extern int64_t g_timer_manager_shutdown_count; extern int64_t g_timer_manager_shutdown_count;
extern int64_t g_fork_count; extern int64_t g_fork_count;
extern int64_t g_timer_wait_err; extern int64_t g_timer_wait_err;
extern int64_t g_timer_wait_cv; extern int64_t g_timer_wait_cv;
#endif // GRPC_DEBUG_TIMER_MANAGER
static void gc_completed_threads(void) { static void gc_completed_threads(void) {
if (g_completed_threads != nullptr) { if (g_completed_threads != nullptr) {
@ -291,10 +292,14 @@ static void start_threads(void) {
} }
void grpc_timer_manager_init(void) { void grpc_timer_manager_init(void) {
#ifdef GRPC_DEBUG_TIMER_MANAGER
// For debug of the timer manager crash only.
// TODO (mxyan): remove after bug is fixed.
g_timer_manager_init_count++;
#endif
gpr_mu_init(&g_mu); gpr_mu_init(&g_mu);
gpr_cv_init(&g_cv_wait); gpr_cv_init(&g_cv_wait);
gpr_cv_init(&g_cv_shutdown); gpr_cv_init(&g_cv_shutdown);
g_timer_manager_init_count++;
g_threaded = false; g_threaded = false;
g_thread_count = 0; g_thread_count = 0;
g_waiter_count = 0; g_waiter_count = 0;
@ -329,7 +334,11 @@ static void stop_threads(void) {
} }
void grpc_timer_manager_shutdown(void) { void grpc_timer_manager_shutdown(void) {
// For debug of the timer manager crash only.
// TODO (mxyan): remove after bug is fixed.
#ifdef GRPC_DEBUG_TIMER_MANAGER
g_timer_manager_shutdown_count++; g_timer_manager_shutdown_count++;
#endif
stop_threads(); stop_threads();
gpr_mu_destroy(&g_mu); gpr_mu_destroy(&g_mu);
@ -338,7 +347,11 @@ void grpc_timer_manager_shutdown(void) {
} }
void grpc_timer_manager_set_threading(bool threaded) { void grpc_timer_manager_set_threading(bool threaded) {
// For debug of the timer manager crash only.
// TODO (mxyan): remove after bug is fixed.
#ifdef GRPC_DEBUG_TIMER_MANAGER
g_fork_count++; g_fork_count++;
#endif
if (threaded) { if (threaded) {
start_threads(); start_threads();
} else { } else {

Loading…
Cancel
Save