diff options
author | Vijay Pai <vpai@google.com> | 2018-02-12 20:06:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-12 20:06:56 -0800 |
commit | 1d168541fd55352be71116a8c8e5c9229b65b2b4 (patch) | |
tree | 8cfebdbea2d906809cd0518ec902c2d9c82dbbe2 /src/core | |
parent | 4a280163f2d783ddf7ea93a646f56e329bda0128 (diff) | |
parent | 236d9f2a285db2d44ba23e7cb1bf7030ebbf9253 (diff) |
Merge pull request #14407 from vjpai/gpr_review_thd
GPR review: Internalize most of gpr_thd (but not ID/current ID)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lib/gpr/thd.cc | 6 | ||||
-rw-r--r-- | src/core/lib/gpr/thd.h | 71 | ||||
-rw-r--r-- | src/core/lib/gpr/thd_internal.h | 30 | ||||
-rw-r--r-- | src/core/lib/gpr/thd_posix.cc | 4 | ||||
-rw-r--r-- | src/core/lib/gpr/thd_windows.cc | 4 | ||||
-rw-r--r-- | src/core/lib/iomgr/ev_poll_posix.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/exec_ctx.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/executor.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/fork_posix.cc | 3 | ||||
-rw-r--r-- | src/core/lib/iomgr/iocp_windows.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/iomgr.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/iomgr_uv.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/iomgr_uv.h | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/pollset_windows.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/resolve_address_posix.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/resolve_address_windows.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/timer_manager.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/wakeup_fd_cv.cc | 2 | ||||
-rw-r--r-- | src/core/lib/profiling/basic_timers.cc | 2 | ||||
-rw-r--r-- | src/core/lib/surface/init.cc | 2 | ||||
-rw-r--r-- | src/core/tsi/alts_transport_security.h | 3 | ||||
-rw-r--r-- | src/core/tsi/ssl_transport_security.cc | 2 |
22 files changed, 99 insertions, 52 deletions
diff --git a/src/core/lib/gpr/thd.cc b/src/core/lib/gpr/thd.cc index ca62615d65..11391418b1 100644 --- a/src/core/lib/gpr/thd.cc +++ b/src/core/lib/gpr/thd.cc @@ -16,11 +16,11 @@ * */ -/* Posix implementation for gpr threads. */ +/* Platform-independent features for gpr threads. */ -#include <string.h> +#include "src/core/lib/gpr/thd.h" -#include <grpc/support/thd.h> +#include <string.h> enum { GPR_THD_JOINABLE = 1 }; diff --git a/src/core/lib/gpr/thd.h b/src/core/lib/gpr/thd.h new file mode 100644 index 0000000000..58ce0d0088 --- /dev/null +++ b/src/core/lib/gpr/thd.h @@ -0,0 +1,71 @@ +/* + * + * 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_GPR_THD_H +#define GRPC_CORE_LIB_GPR_THD_H +/** Internal thread interface for GPR. + + Types + gpr_thd_options options used when creating a thread + */ + +#include <grpc/support/port_platform.h> +#include <grpc/support/thd_id.h> +#include <grpc/support/time.h> + +/** Thread creation options. */ +typedef struct { + int flags; /** Opaque field. Get and set with accessors below. */ +} gpr_thd_options; + +/** Create a new thread running (*thd_body)(arg) and place its thread identifier + in *t, and return true. If there are insufficient resources, return false. + thd_name is the name of the thread for identification purposes on platforms + that support thread naming. + If options==NULL, default options are used. + The thread is immediately runnable, and exits when (*thd_body)() returns. */ +int gpr_thd_new(gpr_thd_id* t, const char* thd_name, + void (*thd_body)(void* arg), void* arg, + const gpr_thd_options* options); + +/** Return a gpr_thd_options struct with all fields set to defaults. */ +gpr_thd_options gpr_thd_options_default(void); + +/** Set the thread to become detached on startup - this is the default. */ +void gpr_thd_options_set_detached(gpr_thd_options* options); + +/** Set the thread to become joinable - mutually exclusive with detached. */ +void gpr_thd_options_set_joinable(gpr_thd_options* options); + +/** Returns non-zero if the option detached is set. */ +int gpr_thd_options_is_detached(const gpr_thd_options* options); + +/** Returns non-zero if the option joinable is set. */ +int gpr_thd_options_is_joinable(const gpr_thd_options* options); + +/** Blocks until the specified thread properly terminates. + Calling this on a detached thread has unpredictable results. */ +void gpr_thd_join(gpr_thd_id t); + +/* Internal interfaces between modules within the gpr support library. */ +void gpr_thd_init(); + +/* Wait for all outstanding threads to finish, up to deadline */ +int gpr_await_threads(gpr_timespec deadline); + +#endif /* GRPC_CORE_LIB_GPR_THD_H */ diff --git a/src/core/lib/gpr/thd_internal.h b/src/core/lib/gpr/thd_internal.h deleted file mode 100644 index 692c00c8e1..0000000000 --- a/src/core/lib/gpr/thd_internal.h +++ /dev/null @@ -1,30 +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_GPR_THD_INTERNAL_H -#define GRPC_CORE_LIB_GPR_THD_INTERNAL_H - -#include <grpc/support/time.h> - -/* Internal interfaces between modules within the gpr support library. */ -void gpr_thd_init(); - -/* Wait for all outstanding threads to finish, up to deadline */ -int gpr_await_threads(gpr_timespec deadline); - -#endif /* GRPC_CORE_LIB_GPR_THD_INTERNAL_H */ diff --git a/src/core/lib/gpr/thd_posix.cc b/src/core/lib/gpr/thd_posix.cc index e8730b9c66..fcd174bfba 100644 --- a/src/core/lib/gpr/thd_posix.cc +++ b/src/core/lib/gpr/thd_posix.cc @@ -22,10 +22,12 @@ #ifdef GPR_POSIX_SYNC +#include "src/core/lib/gpr/thd.h" + #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> +#include <grpc/support/thd_id.h> #include <pthread.h> #include <stdlib.h> #include <string.h> diff --git a/src/core/lib/gpr/thd_windows.cc b/src/core/lib/gpr/thd_windows.cc index f920770f32..b467bd2662 100644 --- a/src/core/lib/gpr/thd_windows.cc +++ b/src/core/lib/gpr/thd_windows.cc @@ -22,9 +22,11 @@ #ifdef GPR_WINDOWS +#include "src/core/lib/gpr/thd.h" + #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include <grpc/support/thd.h> +#include <grpc/support/thd_id.h> #include <string.h> #if defined(_MSC_VER) diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index e92163322f..e630ddf8e0 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -33,10 +33,10 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include <grpc/support/thd.h> #include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/murmur_hash.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/tls.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/block_annotate.h" diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 5401a94dd3..1a2284f474 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -20,8 +20,8 @@ #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/profiling/timers.h" diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 7ab987c19e..d2a050919e 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -24,10 +24,10 @@ #include <grpc/support/cpu.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> #include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/spinlock.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/tls.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/exec_ctx.h" diff --git a/src/core/lib/iomgr/fork_posix.cc b/src/core/lib/iomgr/fork_posix.cc index c581dae1ae..c9a65c5702 100644 --- a/src/core/lib/iomgr/fork_posix.cc +++ b/src/core/lib/iomgr/fork_posix.cc @@ -24,11 +24,10 @@ #include <grpc/fork.h> #include <grpc/support/log.h> -#include <grpc/support/thd.h> #include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/fork.h" -#include "src/core/lib/gpr/thd_internal.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/timer_manager.h" diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index d730ce4624..4716872ce4 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -26,9 +26,9 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/log_windows.h> -#include <grpc/support/thd.h> #include "src/core/lib/debug/stats.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/iocp_windows.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/socket_windows.h" diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 9e407a29a8..70a80e1998 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -28,10 +28,10 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> #include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/executor.h" diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index 9614c2e664..c11bc28ad7 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -20,6 +20,8 @@ #ifdef GRPC_UV +#include <grpc/support/thd_id.h> + #include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/iomgr_uv.h" diff --git a/src/core/lib/iomgr/iomgr_uv.h b/src/core/lib/iomgr/iomgr_uv.h index 3b4daaa73b..a382f0a5ae 100644 --- a/src/core/lib/iomgr/iomgr_uv.h +++ b/src/core/lib/iomgr/iomgr_uv.h @@ -21,7 +21,7 @@ #include "src/core/lib/iomgr/iomgr_internal.h" -#include <grpc/support/thd.h> +#include <grpc/support/thd_id.h> /* The thread ID of the thread on which grpc was initialized. Used to verify * that all calls into libuv are made on that same thread */ diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index 6ef949aad7..240a24dee1 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -21,8 +21,8 @@ #ifdef GRPC_WINSOCK_SOCKET #include <grpc/support/log.h> -#include <grpc/support/thd.h> +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/iocp_windows.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/pollset.h" diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index dd5363dc0a..3dc1d871a1 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -29,11 +29,11 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include <grpc/support/thd.h> #include <grpc/support/time.h> #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/block_annotate.h" #include "src/core/lib/iomgr/executor.h" diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index e875d77fd8..8f4fd04402 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -31,11 +31,11 @@ #include <grpc/support/log.h> #include <grpc/support/log_windows.h> #include <grpc/support/string_util.h> -#include <grpc/support/thd.h> #include <grpc/support/time.h> #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/block_annotate.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/iomgr_internal.h" diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index a528c22264..94e7953fde 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -21,11 +21,11 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/port_platform.h> -#include <grpc/support/thd.h> #include <inttypes.h> #include "src/core/lib/debug/trace.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/iomgr/timer.h" typedef struct completed_thread { diff --git a/src/core/lib/iomgr/wakeup_fd_cv.cc b/src/core/lib/iomgr/wakeup_fd_cv.cc index 59718243e0..41d35cb1fd 100644 --- a/src/core/lib/iomgr/wakeup_fd_cv.cc +++ b/src/core/lib/iomgr/wakeup_fd_cv.cc @@ -28,9 +28,9 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> #include <grpc/support/time.h> +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" #define MAX_TABLE_RESIZE 256 diff --git a/src/core/lib/profiling/basic_timers.cc b/src/core/lib/profiling/basic_timers.cc index d1c9fd7dec..ca6705a6b3 100644 --- a/src/core/lib/profiling/basic_timers.cc +++ b/src/core/lib/profiling/basic_timers.cc @@ -25,12 +25,12 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> #include <grpc/support/time.h> #include <stdio.h> #include <string.h> #include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/thd.h" typedef enum { BEGIN = '{', END = '}', MARK = '.' } marker_type; diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 46bf266740..7bc24a5049 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -32,7 +32,7 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/gpr/fork.h" -#include "src/core/lib/gpr/thd_internal.h" +#include "src/core/lib/gpr/thd.h" #include "src/core/lib/http/parser.h" #include "src/core/lib/iomgr/call_combiner.h" #include "src/core/lib/iomgr/combiner.h" diff --git a/src/core/tsi/alts_transport_security.h b/src/core/tsi/alts_transport_security.h index 5d693d04af..37febd1e28 100644 --- a/src/core/tsi/alts_transport_security.h +++ b/src/core/tsi/alts_transport_security.h @@ -21,7 +21,8 @@ #include <grpc/grpc.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> + +#include "src/core/lib/gpr/thd.h" typedef struct alts_shared_resource { gpr_thd_id thread_id; diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 643b5a5c79..29fd59a0e9 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -36,7 +36,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include <grpc/support/thd.h> +#include <grpc/support/thd_id.h> extern "C" { #include <openssl/bio.h> |