| Index: third_party/grpc/src/core/support/cpu_posix.c
|
| diff --git a/third_party/WebKit/Source/build/win/Precompile.h b/third_party/grpc/src/core/support/cpu_posix.c
|
| similarity index 56%
|
| copy from third_party/WebKit/Source/build/win/Precompile.h
|
| copy to third_party/grpc/src/core/support/cpu_posix.c
|
| index 8a0ff29c353fc1d30c92d27f369d7c422a579bc8..8f01c284ca425ccab9d7f10ac63cbc029f0bfc7f 100644
|
| --- a/third_party/WebKit/Source/build/win/Precompile.h
|
| +++ b/third_party/grpc/src/core/support/cpu_posix.c
|
| @@ -1,5 +1,7 @@
|
| /*
|
| - * Copyright (C) 2012 Google Inc. All rights reserved.
|
| + *
|
| + * 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
|
| @@ -26,43 +28,50 @@
|
| * 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.
|
| - */
|
| -
|
| -/*
|
| - * Precompiled header for WebKit when built on Windows using
|
| - * GYP-generated project files. Not used by other build
|
| - * configurations.
|
| *
|
| - * Using precompiled headers speeds the build up significantly. On a
|
| - * fast machine (HP Z600, 12 GB of RAM), an ~18% decrease in full
|
| - * build time was measured.
|
| */
|
|
|
| -#if defined(WinPrecompile_h_)
|
| -#error You shouldn't include the precompiled header file more than once.
|
| -#endif
|
| +#include <grpc/support/port_platform.h>
|
|
|
| -#define WinPrecompile_h_
|
| -
|
| -#define _USE_MATH_DEFINES // Make math.h behave like other platforms.
|
| -
|
| -#include <Windows.h>
|
| +#ifdef GPR_CPU_POSIX
|
|
|
| #include <errno.h>
|
| -#include <fcntl.h>
|
| -#include <limits.h>
|
| -#include <math.h>
|
| -#include <stdarg.h>
|
| -#include <stddef.h>
|
| -#include <stdio.h>
|
| -#include <stdlib.h>
|
| +#include <unistd.h>
|
| #include <string.h>
|
| -#include <time.h>
|
|
|
| -#include <algorithm>
|
| -#include <ciso646>
|
| -#include <cmath>
|
| -#include <cstddef>
|
| -#include <limits>
|
| -#include <string>
|
| -#include <utility>
|
| +#include <grpc/support/log.h>
|
| +#include <grpc/support/sync.h>
|
| +
|
| +static __thread char magic_thread_local;
|
| +
|
| +static long ncpus = 0;
|
| +
|
| +static void init_ncpus() {
|
| + ncpus = sysconf(_SC_NPROCESSORS_ONLN);
|
| + if (ncpus < 1 || ncpus > INT32_MAX) {
|
| + gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1");
|
| + ncpus = 1;
|
| + }
|
| +}
|
| +
|
| +unsigned gpr_cpu_num_cores(void) {
|
| + static gpr_once once = GPR_ONCE_INIT;
|
| + gpr_once_init(&once, init_ncpus);
|
| + return (unsigned)ncpus;
|
| +}
|
| +
|
| +/* This is a cheap, but good enough, pointer hash for sharding things: */
|
| +static size_t shard_ptr(const void *info) {
|
| + size_t x = (size_t)info;
|
| + return ((x >> 4) ^ (x >> 9) ^ (x >> 14)) % gpr_cpu_num_cores();
|
| +}
|
| +
|
| +unsigned gpr_cpu_current_cpu(void) {
|
| + /* NOTE: there's no way I know to return the actual cpu index portably...
|
| + most code that's using this is using it to shard across work queues though,
|
| + so here we use thread identity instead to achieve a similar though not
|
| + identical effect */
|
| + return (unsigned)shard_ptr(&magic_thread_local);
|
| +}
|
| +
|
| +#endif /* GPR_CPU_POSIX */
|
|
|