aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/support')
-rw-r--r--src/core/lib/support/backoff.cc72
-rw-r--r--src/core/lib/support/backoff.h64
-rw-r--r--src/core/lib/support/block_annotate.h55
-rw-r--r--src/core/lib/support/env_windows.cc5
-rw-r--r--src/core/lib/support/log_android.cc8
-rw-r--r--src/core/lib/support/log_posix.cc2
-rw-r--r--src/core/lib/support/time_posix.cc3
-rw-r--r--src/core/lib/support/time_windows.cc3
8 files changed, 9 insertions, 203 deletions
diff --git a/src/core/lib/support/backoff.cc b/src/core/lib/support/backoff.cc
deleted file mode 100644
index 6dc0df473b..0000000000
--- a/src/core/lib/support/backoff.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- *
- * Copyright 2016 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "src/core/lib/support/backoff.h"
-
-#include <grpc/support/useful.h>
-
-void gpr_backoff_init(gpr_backoff *backoff, int64_t initial_connect_timeout,
- double multiplier, double jitter,
- int64_t min_timeout_millis, int64_t max_timeout_millis) {
- backoff->initial_connect_timeout = initial_connect_timeout;
- backoff->multiplier = multiplier;
- backoff->jitter = jitter;
- backoff->min_timeout_millis = min_timeout_millis;
- backoff->max_timeout_millis = max_timeout_millis;
- backoff->rng_state = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec;
-}
-
-gpr_timespec gpr_backoff_begin(gpr_backoff *backoff, gpr_timespec now) {
- backoff->current_timeout_millis = backoff->initial_connect_timeout;
- const int64_t first_timeout =
- GPR_MAX(backoff->current_timeout_millis, backoff->min_timeout_millis);
- return gpr_time_add(now, gpr_time_from_millis(first_timeout, GPR_TIMESPAN));
-}
-
-/* Generate a random number between 0 and 1. */
-static double generate_uniform_random_number(uint32_t *rng_state) {
- *rng_state = (1103515245 * *rng_state + 12345) % ((uint32_t)1 << 31);
- return *rng_state / (double)((uint32_t)1 << 31);
-}
-
-gpr_timespec gpr_backoff_step(gpr_backoff *backoff, gpr_timespec now) {
- const double new_timeout_millis =
- backoff->multiplier * (double)backoff->current_timeout_millis;
- backoff->current_timeout_millis =
- GPR_MIN((int64_t)new_timeout_millis, backoff->max_timeout_millis);
-
- const double jitter_range_width = backoff->jitter * new_timeout_millis;
- const double jitter =
- (2 * generate_uniform_random_number(&backoff->rng_state) - 1) *
- jitter_range_width;
-
- backoff->current_timeout_millis =
- (int64_t)((double)(backoff->current_timeout_millis) + jitter);
-
- const gpr_timespec current_deadline = gpr_time_add(
- now, gpr_time_from_millis(backoff->current_timeout_millis, GPR_TIMESPAN));
-
- const gpr_timespec min_deadline = gpr_time_add(
- now, gpr_time_from_millis(backoff->min_timeout_millis, GPR_TIMESPAN));
-
- return gpr_time_max(current_deadline, min_deadline);
-}
-
-void gpr_backoff_reset(gpr_backoff *backoff) {
- backoff->current_timeout_millis = backoff->initial_connect_timeout;
-}
diff --git a/src/core/lib/support/backoff.h b/src/core/lib/support/backoff.h
deleted file mode 100644
index 31ec28f666..0000000000
--- a/src/core/lib/support/backoff.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- *
- * Copyright 2016 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef GRPC_CORE_LIB_SUPPORT_BACKOFF_H
-#define GRPC_CORE_LIB_SUPPORT_BACKOFF_H
-
-#include <grpc/support/time.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- /// const: how long to wait after the first failure before retrying
- int64_t initial_connect_timeout;
- /// const: factor with which to multiply backoff after a failed retry
- double multiplier;
- /// const: amount to randomize backoffs
- double jitter;
- /// const: minimum time between retries in milliseconds
- int64_t min_timeout_millis;
- /// const: maximum time between retries in milliseconds
- int64_t max_timeout_millis;
-
- /// random number generator
- uint32_t rng_state;
-
- /// current retry timeout in milliseconds
- int64_t current_timeout_millis;
-} gpr_backoff;
-
-/// Initialize backoff machinery - does not need to be destroyed
-void gpr_backoff_init(gpr_backoff *backoff, int64_t initial_connect_timeout,
- double multiplier, double jitter,
- int64_t min_timeout_millis, int64_t max_timeout_millis);
-
-/// Begin retry loop: returns a timespec for the NEXT retry
-gpr_timespec gpr_backoff_begin(gpr_backoff *backoff, gpr_timespec now);
-/// Step a retry loop: returns a timespec for the NEXT retry
-gpr_timespec gpr_backoff_step(gpr_backoff *backoff, gpr_timespec now);
-/// Reset the backoff, so the next gpr_backoff_step will be a gpr_backoff_begin
-/// instead
-void gpr_backoff_reset(gpr_backoff *backoff);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* GRPC_CORE_LIB_SUPPORT_BACKOFF_H */
diff --git a/src/core/lib/support/block_annotate.h b/src/core/lib/support/block_annotate.h
deleted file mode 100644
index 8e3ef7df65..0000000000
--- a/src/core/lib/support/block_annotate.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *
- * Copyright 2015 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H
-#define GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void gpr_thd_start_blocking_region();
-void gpr_thd_end_blocking_region();
-
-#ifdef __cplusplus
-}
-#endif
-
-/* These annotations identify the beginning and end of regions where
- the code may block for reasons other than synchronization functions.
- These include poll, epoll, and getaddrinfo. */
-
-#ifdef GRPC_SCHEDULING_MARK_BLOCKING_REGION
-#define GRPC_SCHEDULING_START_BLOCKING_REGION \
- do { \
- gpr_thd_start_blocking_region(); \
- } while (0)
-#define GRPC_SCHEDULING_END_BLOCKING_REGION \
- do { \
- gpr_thd_end_blocking_region(); \
- } while (0)
-#else
-#define GRPC_SCHEDULING_START_BLOCKING_REGION \
- do { \
- } while (0)
-#define GRPC_SCHEDULING_END_BLOCKING_REGION \
- do { \
- } while (0)
-#endif
-
-#endif /* GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H */
diff --git a/src/core/lib/support/env_windows.cc b/src/core/lib/support/env_windows.cc
index 73c643c560..c5a25dc201 100644
--- a/src/core/lib/support/env_windows.cc
+++ b/src/core/lib/support/env_windows.cc
@@ -43,7 +43,10 @@ char *gpr_getenv(const char *name) {
DWORD ret;
ret = GetEnvironmentVariable(tname, NULL, 0);
- if (ret == 0) return NULL;
+ if (ret == 0) {
+ gpr_free(tname);
+ return NULL;
+ }
size = ret * (DWORD)sizeof(TCHAR);
tresult = (LPTSTR)gpr_malloc(size);
ret = GetEnvironmentVariable(tname, tresult, size);
diff --git a/src/core/lib/support/log_android.cc b/src/core/lib/support/log_android.cc
index 6f1cec51f1..9e8529cbac 100644
--- a/src/core/lib/support/log_android.cc
+++ b/src/core/lib/support/log_android.cc
@@ -39,8 +39,8 @@ static android_LogPriority severity_to_log_priority(gpr_log_severity severity) {
return ANDROID_LOG_DEFAULT;
}
-void gpr_log(const char *file, int line, gpr_log_severity severity,
- const char *format, ...) {
+extern "C" void gpr_log(const char *file, int line, gpr_log_severity severity,
+ const char *format, ...) {
char *message = NULL;
va_list args;
va_start(args, format);
@@ -50,8 +50,8 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
free(message);
}
-void gpr_default_log(gpr_log_func_args *args) {
- char *final_slash;
+extern "C" void gpr_default_log(gpr_log_func_args *args) {
+ const char *final_slash;
const char *display_file;
char *output = NULL;
diff --git a/src/core/lib/support/log_posix.cc b/src/core/lib/support/log_posix.cc
index 38a136e646..29530c858f 100644
--- a/src/core/lib/support/log_posix.cc
+++ b/src/core/lib/support/log_posix.cc
@@ -58,7 +58,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
}
extern "C" void gpr_default_log(gpr_log_func_args *args) {
- char *final_slash;
+ const char *final_slash;
const char *display_file;
char time_buffer[64];
time_t timer;
diff --git a/src/core/lib/support/time_posix.cc b/src/core/lib/support/time_posix.cc
index deccb50975..3267ea6b54 100644
--- a/src/core/lib/support/time_posix.cc
+++ b/src/core/lib/support/time_posix.cc
@@ -30,7 +30,6 @@
#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
-#include "src/core/lib/support/block_annotate.h"
static struct timespec timespec_from_gpr(gpr_timespec gts) {
struct timespec rv;
@@ -159,9 +158,7 @@ void gpr_sleep_until(gpr_timespec until) {
delta = gpr_time_sub(until, now);
delta_ts = timespec_from_gpr(delta);
- GRPC_SCHEDULING_START_BLOCKING_REGION;
ns_result = nanosleep(&delta_ts, NULL);
- GRPC_SCHEDULING_END_BLOCKING_REGION;
if (ns_result == 0) {
break;
}
diff --git a/src/core/lib/support/time_windows.cc b/src/core/lib/support/time_windows.cc
index dda7566cd8..08c1b22964 100644
--- a/src/core/lib/support/time_windows.cc
+++ b/src/core/lib/support/time_windows.cc
@@ -28,7 +28,6 @@
#include <process.h>
#include <sys/timeb.h>
-#include "src/core/lib/support/block_annotate.h"
#include "src/core/lib/support/time_precise.h"
static LARGE_INTEGER g_start_time;
@@ -94,9 +93,7 @@ void gpr_sleep_until(gpr_timespec until) {
sleep_millis =
delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS;
GPR_ASSERT((sleep_millis >= 0) && (sleep_millis <= INT_MAX));
- GRPC_SCHEDULING_START_BLOCKING_REGION;
Sleep((DWORD)sleep_millis);
- GRPC_SCHEDULING_END_BLOCKING_REGION;
}
}