diff options
Diffstat (limited to 'src/core')
25 files changed, 165 insertions, 96 deletions
diff --git a/src/core/client_config/subchannel_index.c b/src/core/client_config/subchannel_index.c index f78a7fd588..3f948998f9 100644 --- a/src/core/client_config/subchannel_index.c +++ b/src/core/client_config/subchannel_index.c @@ -149,11 +149,13 @@ static const gpr_avl_vtable subchannel_avl_vtable = { void grpc_subchannel_index_init(void) { g_subchannel_index = gpr_avl_create(&subchannel_avl_vtable); gpr_mu_init(&g_mu); + gpr_tls_init(&subchannel_index_exec_ctx); } void grpc_subchannel_index_shutdown(void) { gpr_mu_destroy(&g_mu); gpr_avl_unref(g_subchannel_index); + gpr_tls_destroy(&subchannel_index_exec_ctx); } grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx, diff --git a/src/core/compression/algorithm.c b/src/core/compression/compression_algorithm.c index 6f3a8eb28e..6f3a8eb28e 100644 --- a/src/core/compression/algorithm.c +++ b/src/core/compression/compression_algorithm.c diff --git a/src/core/httpcli/httpcli.c b/src/core/httpcli/httpcli.c index 68fa8c8cf5..1219c444c7 100644 --- a/src/core/httpcli/httpcli.c +++ b/src/core/httpcli/httpcli.c @@ -39,9 +39,11 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> + #include "src/core/httpcli/format_request.h" #include "src/core/httpcli/parser.h" #include "src/core/iomgr/endpoint.h" +#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/resolve_address.h" #include "src/core/iomgr/tcp_client.h" #include "src/core/support/string.h" diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c index 812ff0992e..4ba7c5df94 100644 --- a/src/core/iomgr/fd_posix.c +++ b/src/core/iomgr/fd_posix.c @@ -177,11 +177,11 @@ int grpc_fd_is_orphaned(grpc_fd *fd) { } static void pollset_kick_locked(grpc_fd_watcher *watcher) { - gpr_mu_lock(watcher->pollset->mu); + gpr_mu_lock(&watcher->pollset->mu); GPR_ASSERT(watcher->worker); grpc_pollset_kick_ext(watcher->pollset, watcher->worker, GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP); - gpr_mu_unlock(watcher->pollset->mu); + gpr_mu_unlock(&watcher->pollset->mu); } static void maybe_wake_one_watcher_locked(grpc_fd *fd) { diff --git a/src/core/iomgr/pollset.h b/src/core/iomgr/pollset.h index 39e4ff2440..92a0374ddd 100644 --- a/src/core/iomgr/pollset.h +++ b/src/core/iomgr/pollset.h @@ -53,7 +53,7 @@ typedef struct grpc_pollset grpc_pollset; typedef struct grpc_pollset_worker grpc_pollset_worker; size_t grpc_pollset_size(void); -void grpc_pollset_init(grpc_pollset *pollset, gpr_mu *mu); +void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu); /* Begin shutting down the pollset, and call closure when done. * GRPC_POLLSET_MU(pollset) must be held */ void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, diff --git a/src/core/iomgr/pollset_multipoller_with_epoll.c b/src/core/iomgr/pollset_multipoller_with_epoll.c index e1af2b5241..2e0f27fab8 100644 --- a/src/core/iomgr/pollset_multipoller_with_epoll.c +++ b/src/core/iomgr/pollset_multipoller_with_epoll.c @@ -149,7 +149,7 @@ static void perform_delayed_add(grpc_exec_ctx *exec_ctx, void *arg, finally_add_fd(exec_ctx, da->pollset, da->fd); } - gpr_mu_lock(da->pollset->mu); + gpr_mu_lock(&da->pollset->mu); da->pollset->in_flight_cbs--; if (da->pollset->shutting_down) { /* We don't care about this pollset anymore. */ @@ -158,7 +158,7 @@ static void perform_delayed_add(grpc_exec_ctx *exec_ctx, void *arg, grpc_exec_ctx_enqueue(exec_ctx, da->pollset->shutdown_done, true, NULL); } } - gpr_mu_unlock(da->pollset->mu); + gpr_mu_unlock(&da->pollset->mu); GRPC_FD_UNREF(da->fd, "delayed_add"); @@ -170,7 +170,7 @@ static void multipoll_with_epoll_pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_fd *fd, int and_unlock_pollset) { if (and_unlock_pollset) { - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); finally_add_fd(exec_ctx, pollset, fd); } else { delayed_add *da = gpr_malloc(sizeof(*da)); @@ -202,7 +202,7 @@ static void multipoll_with_epoll_pollset_maybe_work_and_unlock( * here. */ - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); timeout_ms = grpc_poll_deadline_to_millis_timeout(deadline, now); diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index 348d339104..4dddfff230 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -80,7 +80,7 @@ static void multipoll_with_poll_pollset_add_fd(grpc_exec_ctx *exec_ctx, GRPC_FD_REF(fd, "multipoller"); exit: if (and_unlock_pollset) { - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); } } @@ -132,7 +132,7 @@ static void multipoll_with_poll_pollset_maybe_work_and_unlock( } h->del_count = 0; h->fd_count = fd_count; - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); for (i = 2; i < pfd_count; i++) { pfds[i].events = (short)grpc_fd_begin_poll(watchers[i].fd, pollset, worker, diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 63321638ba..e895a77884 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -188,8 +188,9 @@ void grpc_kick_poller(void) { grpc_wakeup_fd_wakeup(&grpc_global_wakeup_fd); } static void become_basic_pollset(grpc_pollset *pollset, grpc_fd *fd_or_null); -void grpc_pollset_init(grpc_pollset *pollset, gpr_mu *mu) { - pollset->mu = mu; +void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu) { + gpr_mu_init(&pollset->mu); + *mu = &pollset->mu; pollset->root_worker.next = pollset->root_worker.prev = &pollset->root_worker; pollset->in_flight_cbs = 0; pollset->shutting_down = 0; @@ -228,15 +229,15 @@ void grpc_pollset_reset(grpc_pollset *pollset) { void grpc_pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, grpc_fd *fd) { - gpr_mu_lock(pollset->mu); + gpr_mu_lock(&pollset->mu); pollset->vtable->add_fd(exec_ctx, pollset, fd, 1); /* the following (enabled only in debug) will reacquire and then release our lock - meaning that if the unlocking flag passed to add_fd above is not respected, the code will deadlock (in a way that we have a chance of debugging) */ #ifndef NDEBUG - gpr_mu_lock(pollset->mu); - gpr_mu_unlock(pollset->mu); + gpr_mu_lock(&pollset->mu); + gpr_mu_unlock(&pollset->mu); #endif } @@ -285,7 +286,7 @@ void grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, /* Give do_promote priority so we don't starve it out */ if (pollset->in_flight_cbs) { GPR_TIMER_MARK("grpc_pollset_work.in_flight_cbs", 0); - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); locked = 0; goto done; } @@ -319,7 +320,7 @@ void grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, done: if (!locked) { queued_work |= grpc_exec_ctx_flush(exec_ctx); - gpr_mu_lock(pollset->mu); + gpr_mu_lock(&pollset->mu); locked = 1; } /* If we're forced to re-evaluate polling (via grpc_pollset_kick with @@ -349,19 +350,19 @@ void grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, grpc_pollset_kick(pollset, NULL); } else if (!pollset->called_shutdown && pollset->in_flight_cbs == 0) { pollset->called_shutdown = 1; - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); finish_shutdown(exec_ctx, pollset); grpc_exec_ctx_flush(exec_ctx); /* Continuing to access pollset here is safe -- it is the caller's * responsibility to not destroy when it has outstanding calls to * grpc_pollset_work. * TODO(dklempner): Can we refactor the shutdown logic to avoid this? */ - gpr_mu_lock(pollset->mu); + gpr_mu_lock(&pollset->mu); } else if (!grpc_closure_list_empty(pollset->idle_jobs)) { grpc_exec_ctx_enqueue_list(exec_ctx, &pollset->idle_jobs, NULL); - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); grpc_exec_ctx_flush(exec_ctx); - gpr_mu_lock(pollset->mu); + gpr_mu_lock(&pollset->mu); } } *worker_hdl = NULL; @@ -429,7 +430,7 @@ static void basic_do_promote(grpc_exec_ctx *exec_ctx, void *args, * 4. The pollset may be shutting down. */ - gpr_mu_lock(pollset->mu); + gpr_mu_lock(&pollset->mu); /* First we need to ensure that nobody is polling concurrently */ GPR_ASSERT(!grpc_pollset_has_workers(pollset)); @@ -470,7 +471,7 @@ static void basic_do_promote(grpc_exec_ctx *exec_ctx, void *args, } } - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); /* Matching ref in basic_pollset_add_fd */ GRPC_FD_UNREF(fd, "basicpoll_add"); @@ -523,7 +524,7 @@ static void basic_pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, exit: if (and_unlock_pollset) { - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); } } @@ -559,14 +560,14 @@ static void basic_pollset_maybe_work_and_unlock(grpc_exec_ctx *exec_ctx, pfd[2].fd = fd->fd; pfd[2].revents = 0; GRPC_FD_REF(fd, "basicpoll_begin"); - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); pfd[2].events = (short)grpc_fd_begin_poll(fd, pollset, worker, POLLIN, POLLOUT, &fd_watcher); if (pfd[2].events != 0) { nfds++; } } else { - gpr_mu_unlock(pollset->mu); + gpr_mu_unlock(&pollset->mu); } /* TODO(vpai): Consider first doing a 0 timeout poll here to avoid diff --git a/src/core/iomgr/pollset_posix.h b/src/core/iomgr/pollset_posix.h index ed7eb5cb7d..bbedb66b00 100644 --- a/src/core/iomgr/pollset_posix.h +++ b/src/core/iomgr/pollset_posix.h @@ -69,7 +69,7 @@ struct grpc_pollset { For example, we may choose a poll() based implementation on linux for few fds, and an epoll() based implementation for many fds */ const grpc_pollset_vtable *vtable; - gpr_mu *mu; + gpr_mu mu; grpc_pollset_worker root_worker; int in_flight_cbs; int shutting_down; diff --git a/src/core/iomgr/pollset_windows.c b/src/core/iomgr/pollset_windows.c index bbce23b46a..651f8e7334 100644 --- a/src/core/iomgr/pollset_windows.c +++ b/src/core/iomgr/pollset_windows.c @@ -89,12 +89,17 @@ static void push_front_worker(grpc_pollset_worker *root, worker->links[type].next->links[type].prev = worker; } +size_t grpc_pollset_size(void) { + return sizeof(grpc_pollset); +} + /* There isn't really any such thing as a pollset under Windows, due to the nature of the IO completion ports. We're still going to provide a minimal set of features for the sake of the rest of grpc. But grpc_pollset_work won't actually do any polling, and return as quickly as possible. */ -void grpc_pollset_init(grpc_pollset *pollset) { +void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu) { + *mu = &grpc_polling_mu; memset(pollset, 0, sizeof(*pollset)); pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].next = pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].prev = diff --git a/src/core/iomgr/pollset_windows.h b/src/core/iomgr/pollset_windows.h index c2f13fdfa8..dc0b7a4104 100644 --- a/src/core/iomgr/pollset_windows.h +++ b/src/core/iomgr/pollset_windows.h @@ -72,6 +72,4 @@ struct grpc_pollset { grpc_closure *on_shutdown; }; -extern gpr_mu grpc_polling_mu; - #endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_WINDOWS_H */ diff --git a/src/core/iomgr/udp_server.h b/src/core/iomgr/udp_server.h index 73a21c80ab..a9d0489edf 100644 --- a/src/core/iomgr/udp_server.h +++ b/src/core/iomgr/udp_server.h @@ -35,6 +35,7 @@ #define GRPC_INTERNAL_CORE_IOMGR_UDP_SERVER_H #include "src/core/iomgr/endpoint.h" +#include "src/core/iomgr/fd_posix.h" /* Forward decl of grpc_server */ typedef struct grpc_server grpc_server; diff --git a/src/core/security/base64.c b/src/core/security/b64.c index 8367c160c3..c40b528e2f 100644 --- a/src/core/security/base64.c +++ b/src/core/security/b64.c @@ -31,7 +31,7 @@ * */ -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include <stdint.h> #include <string.h> diff --git a/src/core/security/base64.h b/src/core/security/b64.h index 31ae982691..3e3b521120 100644 --- a/src/core/security/base64.h +++ b/src/core/security/b64.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/core/security/google_default_credentials.c b/src/core/security/google_default_credentials.c index 25006e16c7..1f4f3e4aa5 100644 --- a/src/core/security/google_default_credentials.c +++ b/src/core/security/google_default_credentials.c @@ -41,7 +41,7 @@ #include "src/core/httpcli/httpcli.h" #include "src/core/support/env.h" -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include "src/core/surface/api_trace.h" /* -- Constants. -- */ @@ -52,10 +52,11 @@ static grpc_channel_credentials *default_credentials = NULL; static int compute_engine_detection_done = 0; -static gpr_mu g_mu; +static gpr_mu g_state_mu; +static gpr_mu *g_polling_mu; static gpr_once g_once = GPR_ONCE_INIT; -static void init_default_credentials(void) { gpr_mu_init(&g_mu); } +static void init_default_credentials(void) { gpr_mu_init(&g_state_mu); } typedef struct { grpc_pollset *pollset; @@ -80,10 +81,10 @@ static void on_compute_engine_detection_http_response( } } } - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_polling_mu); detector->is_done = 1; grpc_pollset_kick(detector->pollset, NULL); - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_polling_mu); } static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool s) { @@ -102,7 +103,7 @@ static int is_stack_running_on_compute_engine(void) { gpr_timespec max_detection_delay = gpr_time_from_seconds(1, GPR_TIMESPAN); detector.pollset = gpr_malloc(grpc_pollset_size()); - grpc_pollset_init(detector.pollset, &g_mu); + grpc_pollset_init(detector.pollset, &g_polling_mu); detector.is_done = 0; detector.success = 0; @@ -121,19 +122,20 @@ static int is_stack_running_on_compute_engine(void) { /* Block until we get the response. This is not ideal but this should only be called once for the lifetime of the process by the default credentials. */ - gpr_mu_lock(&g_mu); + gpr_mu_lock(g_polling_mu); while (!detector.is_done) { grpc_pollset_worker *worker = NULL; grpc_pollset_work(&exec_ctx, detector.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(g_polling_mu); grpc_httpcli_context_destroy(&context); - grpc_closure_init(&destroy_closure, destroy_pollset, &detector.pollset); + grpc_closure_init(&destroy_closure, destroy_pollset, detector.pollset); grpc_pollset_shutdown(&exec_ctx, detector.pollset, &destroy_closure); grpc_exec_ctx_finish(&exec_ctx); + g_polling_mu = NULL; gpr_free(detector.pollset); @@ -187,7 +189,7 @@ grpc_channel_credentials *grpc_google_default_credentials_create(void) { gpr_once_init(&g_once, init_default_credentials); - gpr_mu_lock(&g_mu); + gpr_mu_lock(&g_state_mu); if (default_credentials != NULL) { result = grpc_channel_credentials_ref(default_credentials); @@ -233,19 +235,19 @@ end: gpr_log(GPR_ERROR, "Could not create google default credentials."); } } - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(&g_state_mu); return result; } void grpc_flush_cached_google_default_credentials(void) { gpr_once_init(&g_once, init_default_credentials); - gpr_mu_lock(&g_mu); + gpr_mu_lock(&g_state_mu); if (default_credentials != NULL) { grpc_channel_credentials_unref(default_credentials); default_credentials = NULL; } compute_engine_detection_done = 0; - gpr_mu_unlock(&g_mu); + gpr_mu_unlock(&g_state_mu); } /* -- Well known credentials path. -- */ diff --git a/src/core/security/json_token.c b/src/core/security/json_token.c index 762f02989a..372e5bfc5a 100644 --- a/src/core/security/json_token.c +++ b/src/core/security/json_token.c @@ -39,7 +39,7 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include "src/core/support/string.h" #include <openssl/bio.h> diff --git a/src/core/security/jwt_verifier.c b/src/core/security/jwt_verifier.c index 042a117f5d..928c6c148d 100644 --- a/src/core/security/jwt_verifier.c +++ b/src/core/security/jwt_verifier.c @@ -37,7 +37,7 @@ #include <string.h> #include "src/core/httpcli/httpcli.h" -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include "src/core/tsi/ssl_types.h" #include <grpc/support/alloc.h> diff --git a/src/core/security/security_connector.c b/src/core/security/security_connector.c index b46205323b..51a99b4492 100644 --- a/src/core/security/security_connector.c +++ b/src/core/security/security_connector.c @@ -35,20 +35,20 @@ #include <string.h> +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> +#include <grpc/support/slice_buffer.h> +#include <grpc/support/string_util.h> + #include "src/core/security/credentials.h" #include "src/core/security/handshake.h" #include "src/core/security/secure_endpoint.h" #include "src/core/security/security_context.h" #include "src/core/support/env.h" -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include "src/core/support/string.h" #include "src/core/transport/chttp2/alpn.h" - -#include <grpc/support/alloc.h> -#include <grpc/support/host_port.h> -#include <grpc/support/log.h> -#include <grpc/support/slice_buffer.h> -#include <grpc/support/string_util.h> #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/ssl_transport_security.h" diff --git a/src/core/support/env_linux.c b/src/core/support/env_linux.c index 1ca6fa1aff..fe51f846b7 100644 --- a/src/core/support/env_linux.c +++ b/src/core/support/env_linux.c @@ -43,7 +43,9 @@ #include "src/core/support/env.h" #include <dlfcn.h> +#include <features.h> #include <stdlib.h> +#include <string.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> @@ -60,12 +62,22 @@ char *gpr_getenv(const char *name) { const char *names[] = {"secure_getenv", "__secure_getenv", "getenv"}; for (size_t i = 0; getenv_func == NULL && i < GPR_ARRAY_SIZE(names); i++) { getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]); + if (getenv_func != NULL && strstr(names[i], "secure") == NULL) { + gpr_log(GPR_DEBUG, + "Warning: insecure environment read function '%s' used", + names[i]); + } } char *result = getenv_func(name); return result == NULL ? result : gpr_strdup(result); -#else +#elif __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) char *result = secure_getenv(name); return result == NULL ? result : gpr_strdup(result); +#else + gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used", + "getenv"); + char *result = getenv(name); + return result == NULL ? result : gpr_strdup(result); #endif } diff --git a/src/core/support/file.c b/src/core/support/load_file.c index 8c673dbcc6..650bd62ccb 100644 --- a/src/core/support/file.c +++ b/src/core/support/load_file.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,7 @@ * */ -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include <errno.h> #include <string.h> diff --git a/src/core/support/file.h b/src/core/support/load_file.h index d8b7cea44f..746319a50d 100644 --- a/src/core/support/file.h +++ b/src/core/support/load_file.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,8 +31,8 @@ * */ -#ifndef GRPC_INTERNAL_CORE_SUPPORT_FILE_H -#define GRPC_INTERNAL_CORE_SUPPORT_FILE_H +#ifndef GRPC_INTERNAL_CORE_SUPPORT_LOAD_FILE_H +#define GRPC_INTERNAL_CORE_SUPPORT_LOAD_FILE_H #include <stdio.h> @@ -42,22 +42,14 @@ extern "C" { #endif -/* File utility functions */ - /* Loads the content of a file into a slice. add_null_terminator will add a NULL terminator if non-zero. The success parameter, if not NULL, will be set to 1 in case of success and 0 in case of failure. */ gpr_slice gpr_load_file(const char *filename, int add_null_terminator, int *success); -/* Creates a temporary file from a prefix. - If tmp_filename is not NULL, *tmp_filename is assigned the name of the - created file and it is the responsibility of the caller to gpr_free it - unless an error occurs in which case it will be set to NULL. */ -FILE *gpr_tmpfile(const char *prefix, char **tmp_filename); - #ifdef __cplusplus } #endif -#endif /* GRPC_INTERNAL_CORE_SUPPORT_FILE_H */ +#endif /* GRPC_INTERNAL_CORE_SUPPORT_LOAD_FILE_H */ diff --git a/src/core/support/tmpfile.h b/src/core/support/tmpfile.h new file mode 100644 index 0000000000..cecc71e242 --- /dev/null +++ b/src/core/support/tmpfile.h @@ -0,0 +1,55 @@ +/* + * + * Copyright 2015-2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_INTERNAL_CORE_SUPPORT_TMPFILE_H +#define GRPC_INTERNAL_CORE_SUPPORT_TMPFILE_H + +#include <stdio.h> + +#include <grpc/support/slice.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Creates a temporary file from a prefix. + If tmp_filename is not NULL, *tmp_filename is assigned the name of the + created file and it is the responsibility of the caller to gpr_free it + unless an error occurs in which case it will be set to NULL. */ +FILE *gpr_tmpfile(const char *prefix, char **tmp_filename); + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_INTERNAL_CORE_SUPPORT_TMPFILE_H */ diff --git a/src/core/support/file_posix.c b/src/core/support/tmpfile_posix.c index c11c07148a..b16eeacf9d 100644 --- a/src/core/support/file_posix.c +++ b/src/core/support/tmpfile_posix.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,7 +35,7 @@ #ifdef GPR_POSIX_FILE -#include "src/core/support/file.h" +#include "src/core/support/tmpfile.h" #include <errno.h> #include <stdlib.h> diff --git a/src/core/support/file_win32.c b/src/core/support/tmpfile_win32.c index 355744f79a..3000f0029f 100644 --- a/src/core/support/file_win32.c +++ b/src/core/support/tmpfile_win32.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,8 +44,8 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include "src/core/support/file.h" #include "src/core/support/string_win32.h" +#include "src/core/support/tmpfile.h" FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) { FILE *result = NULL; diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c index 41449fb4a6..8a9bbace08 100644 --- a/src/core/surface/completion_queue.c +++ b/src/core/surface/completion_queue.c @@ -57,7 +57,8 @@ typedef struct { /* Completion queue structure */ struct grpc_completion_queue { - gpr_mu mu; + /** owned by pollset */ + gpr_mu *mu; /** completed events */ grpc_cq_completion completed_head; grpc_cq_completion *completed_tail; @@ -97,7 +98,6 @@ void grpc_cq_global_shutdown(void) { while (g_freelist) { grpc_completion_queue *next = g_freelist->next_free; grpc_pollset_destroy(POLLSET_FROM_CQ(g_freelist)); - gpr_mu_destroy(&g_freelist->mu); #ifndef NDEBUG gpr_free(g_freelist->outstanding_tags); #endif @@ -128,7 +128,6 @@ grpc_completion_queue *grpc_completion_queue_create(void *reserved) { gpr_mu_unlock(&g_freelist_mu); cc = gpr_malloc(sizeof(grpc_completion_queue) + grpc_pollset_size()); - gpr_mu_init(&cc->mu); grpc_pollset_init(POLLSET_FROM_CQ(cc), &cc->mu); #ifndef NDEBUG cc->outstanding_tags = NULL; @@ -198,7 +197,7 @@ void grpc_cq_internal_unref(grpc_completion_queue *cc) { void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag) { #ifndef NDEBUG - gpr_mu_lock(&cc->mu); + gpr_mu_lock(cc->mu); GPR_ASSERT(!cc->shutdown_called); if (cc->outstanding_tag_count == cc->outstanding_tag_capacity) { cc->outstanding_tag_capacity = GPR_MAX(4, 2 * cc->outstanding_tag_capacity); @@ -207,7 +206,7 @@ void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag) { cc->outstanding_tag_capacity); } cc->outstanding_tags[cc->outstanding_tag_count++] = tag; - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); #endif gpr_ref(&cc->pending_events); } @@ -235,7 +234,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, storage->next = ((uintptr_t)&cc->completed_head) | ((uintptr_t)(success != 0)); - gpr_mu_lock(&cc->mu); + gpr_mu_lock(cc->mu); #ifndef NDEBUG for (i = 0; i < (int)cc->outstanding_tag_count; i++) { if (cc->outstanding_tags[i] == tag) { @@ -261,7 +260,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, } } grpc_pollset_kick(POLLSET_FROM_CQ(cc), pluck_worker); - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); } else { cc->completed_tail->next = ((uintptr_t)storage) | (1u & (uintptr_t)cc->completed_tail->next); @@ -271,7 +270,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, cc->shutdown = 1; grpc_pollset_shutdown(exec_ctx, POLLSET_FROM_CQ(cc), &cc->pollset_shutdown_done); - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); } GPR_TIMER_END("grpc_cq_end_op", 0); @@ -299,7 +298,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); GRPC_CQ_INTERNAL_REF(cc, "next"); - gpr_mu_lock(&cc->mu); + gpr_mu_lock(cc->mu); for (;;) { if (cc->completed_tail != &cc->completed_head) { grpc_cq_completion *c = (grpc_cq_completion *)cc->completed_head.next; @@ -307,7 +306,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, if (c == cc->completed_tail) { cc->completed_tail = &cc->completed_head; } - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; @@ -315,14 +314,14 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, break; } if (cc->shutdown) { - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_SHUTDOWN; break; } now = gpr_now(GPR_CLOCK_MONOTONIC); if (!first_loop && gpr_time_cmp(now, deadline) >= 0) { - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; break; @@ -335,9 +334,9 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, gpr_timespec iteration_deadline = deadline; if (grpc_timer_check(&exec_ctx, now, &iteration_deadline)) { GPR_TIMER_MARK("alarm_triggered", 0); - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(&cc->mu); + gpr_mu_lock(cc->mu); continue; } else { grpc_pollset_work(&exec_ctx, POLLSET_FROM_CQ(cc), &worker, now, @@ -401,7 +400,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC); GRPC_CQ_INTERNAL_REF(cc, "pluck"); - gpr_mu_lock(&cc->mu); + gpr_mu_lock(cc->mu); for (;;) { prev = &cc->completed_head; while ((c = (grpc_cq_completion *)(prev->next & ~(uintptr_t)1)) != @@ -411,7 +410,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, if (c == cc->completed_tail) { cc->completed_tail = prev; } - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; @@ -421,7 +420,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, prev = c; } if (cc->shutdown) { - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_SHUTDOWN; break; @@ -431,7 +430,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, "Too many outstanding grpc_completion_queue_pluck calls: maximum " "is %d", GRPC_MAX_COMPLETION_QUEUE_PLUCKERS); - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); memset(&ret, 0, sizeof(ret)); /* TODO(ctiller): should we use a different result here */ ret.type = GRPC_QUEUE_TIMEOUT; @@ -440,7 +439,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, now = gpr_now(GPR_CLOCK_MONOTONIC); if (!first_loop && gpr_time_cmp(now, deadline) >= 0) { del_plucker(cc, tag, &worker); - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; break; @@ -453,9 +452,9 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, gpr_timespec iteration_deadline = deadline; if (grpc_timer_check(&exec_ctx, now, &iteration_deadline)) { GPR_TIMER_MARK("alarm_triggered", 0); - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); grpc_exec_ctx_flush(&exec_ctx); - gpr_mu_lock(&cc->mu); + gpr_mu_lock(cc->mu); continue; } else { grpc_pollset_work(&exec_ctx, POLLSET_FROM_CQ(cc), &worker, now, @@ -479,9 +478,9 @@ void grpc_completion_queue_shutdown(grpc_completion_queue *cc) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cc=%p)", 1, (cc)); - gpr_mu_lock(&cc->mu); + gpr_mu_lock(cc->mu); if (cc->shutdown_called) { - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); GPR_TIMER_END("grpc_completion_queue_shutdown", 0); return; } @@ -492,7 +491,7 @@ void grpc_completion_queue_shutdown(grpc_completion_queue *cc) { grpc_pollset_shutdown(&exec_ctx, POLLSET_FROM_CQ(cc), &cc->pollset_shutdown_done); } - gpr_mu_unlock(&cc->mu); + gpr_mu_unlock(cc->mu); grpc_exec_ctx_finish(&exec_ctx); GPR_TIMER_END("grpc_completion_queue_shutdown", 0); } |