From 4a0a394758d4f169173c221fe58284fee65970e4 Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Tue, 3 Feb 2015 15:04:45 -0800 Subject: Fixing tsan errors in OpenSSL (#319) - Added cross-platform implementation of gpr_thd_currentid(); - OpenSSL still shows some TSAN errors on OPENSSL_cleanse which is inherently not thread-safe but this should not matter: see http://stackoverflow.com/questions/26433772/why-does-openssl-cleanse-look-so-complex-and-thread-unsafe --- src/core/support/thd_posix.c | 8 +++++++- src/core/support/thd_win32.c | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/core/support') diff --git a/src/core/support/thd_posix.c b/src/core/support/thd_posix.c index bac1d9c220..74ca9424bb 100644 --- a/src/core/support/thd_posix.c +++ b/src/core/support/thd_posix.c @@ -62,17 +62,19 @@ int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg, const gpr_thd_options *options) { int thread_started; pthread_attr_t attr; + pthread_t p; struct thd_arg *a = gpr_malloc(sizeof(*a)); a->body = thd_body; a->arg = arg; GPR_ASSERT(pthread_attr_init(&attr) == 0); GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0); - thread_started = (pthread_create(t, &attr, &thread_body, a) == 0); + thread_started = (pthread_create(&p, &attr, &thread_body, a) == 0); GPR_ASSERT(pthread_attr_destroy(&attr) == 0); if (!thread_started) { gpr_free(a); } + *t = (gpr_thd_id)p; return thread_started; } @@ -82,4 +84,8 @@ gpr_thd_options gpr_thd_options_default(void) { return options; } +gpr_thd_id gpr_thd_currentid(void) { + return (gpr_thd_id)pthread_self(); +} + #endif /* GPR_POSIX_SYNC */ diff --git a/src/core/support/thd_win32.c b/src/core/support/thd_win32.c index 1762f87f3c..9378f91d21 100644 --- a/src/core/support/thd_win32.c +++ b/src/core/support/thd_win32.c @@ -77,4 +77,8 @@ gpr_thd_options gpr_thd_options_default(void) { return options; } +gpr_thd_id gpr_thd_currentid(void) { + return (gpr_thd_id)GetCurrentThreadId(); +} + #endif /* GPR_WIN32 */ -- cgit v1.2.3 From 57db88f1164314c3680a7a9c60dc36b47c8901f9 Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Tue, 3 Feb 2015 16:29:31 -0800 Subject: Addressing nicolasnoble@ comments. --- src/core/support/thd_win32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/core/support') diff --git a/src/core/support/thd_win32.c b/src/core/support/thd_win32.c index 9378f91d21..2ee1417048 100644 --- a/src/core/support/thd_win32.c +++ b/src/core/support/thd_win32.c @@ -58,16 +58,18 @@ static DWORD WINAPI thread_body(void *v) { int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg, const gpr_thd_options *options) { HANDLE handle; + DWORD thread_id; struct thd_arg *a = gpr_malloc(sizeof(*a)); a->body = thd_body; a->arg = arg; *t = 0; - handle = CreateThread(NULL, 64 * 1024, thread_body, a, 0, NULL); + handle = CreateThread(NULL, 64 * 1024, thread_body, a, 0, &thread_id); if (handle == NULL) { gpr_free(a); } else { CloseHandle(handle); /* threads are "detached" */ } + *t = (gpr_thd_id)thread_id; return handle != NULL; } -- cgit v1.2.3 From c15622b95c8162cf981aa63caf8d764ab1718b09 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Wed, 4 Feb 2015 12:02:17 -0800 Subject: Remove timeval functions They only had one caller, which could easily be converted to use timespec instead of timeval. --- include/grpc/support/time.h | 4 ---- src/core/support/time.c | 16 ---------------- src/node/ext/timeval.cc | 5 ++--- 3 files changed, 2 insertions(+), 23 deletions(-) (limited to 'src/core/support') diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h index 6327a2cffb..f8870153b1 100644 --- a/include/grpc/support/time.h +++ b/include/grpc/support/time.h @@ -103,10 +103,6 @@ int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold); /* Sleep until at least 'until' - an absolute timeout */ void gpr_sleep_until(gpr_timespec until); -struct timeval gpr_timeval_from_timespec(gpr_timespec t); - -gpr_timespec gpr_timespec_from_timeval(struct timeval t); - double gpr_timespec_to_micros(gpr_timespec t); #ifdef __cplusplus diff --git a/src/core/support/time.c b/src/core/support/time.c index 97243318fd..268a43c677 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -234,22 +234,6 @@ int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold) { } } -struct timeval gpr_timeval_from_timespec(gpr_timespec t) { - /* TODO(klempner): Consider whether this should round up, since it is likely - to be used for delays */ - struct timeval tv; - tv.tv_sec = t.tv_sec; - tv.tv_usec = t.tv_nsec / 1000; - return tv; -} - -gpr_timespec gpr_timespec_from_timeval(struct timeval t) { - gpr_timespec ts; - ts.tv_sec = t.tv_sec; - ts.tv_nsec = t.tv_usec * 1000; - return ts; -} - gpr_int32 gpr_time_to_millis(gpr_timespec t) { if (t.tv_sec >= 2147483) { if (t.tv_sec == 2147483 && t.tv_nsec < 648 * GPR_NS_PER_MS) { diff --git a/src/node/ext/timeval.cc b/src/node/ext/timeval.cc index 687e33576b..20d52f0963 100644 --- a/src/node/ext/timeval.cc +++ b/src/node/ext/timeval.cc @@ -56,9 +56,8 @@ double TimespecToMilliseconds(gpr_timespec timespec) { } else if (gpr_time_cmp(timespec, gpr_inf_past) == 0) { return -std::numeric_limits::infinity(); } else { - struct timeval time = gpr_timeval_from_timespec(timespec); - return (static_cast(time.tv_sec) * 1000 + - static_cast(time.tv_usec) / 1000); + return (static_cast(timespec.tv_sec) * 1000 + + static_cast(timespec.tv_nsec) / 1000000); } } -- cgit v1.2.3