aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support/cpu_posix.c
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2017-02-13 15:49:27 -0800
committerGravatar yang-g <yangg@google.com>2017-02-16 09:39:27 -0800
commit6955c5e8d2c881169dfa4ffd80a38182d6e2e14e (patch)
tree02d0b640bf48aa526d21e5ad0d8bdd1f08c3ce5a /src/core/lib/support/cpu_posix.c
parentee31910271a72c4e454a9d64ceafa530566388a6 (diff)
Remove code from network_status_tracker.c Pull the hash function to useful.h
Diffstat (limited to 'src/core/lib/support/cpu_posix.c')
-rw-r--r--src/core/lib/support/cpu_posix.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/core/lib/support/cpu_posix.c b/src/core/lib/support/cpu_posix.c
index 667bde7cad..245f12f06d 100644
--- a/src/core/lib/support/cpu_posix.c
+++ b/src/core/lib/support/cpu_posix.c
@@ -41,6 +41,7 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
+#include <grpc/support/useful.h>
static __thread char magic_thread_local;
@@ -60,18 +61,12 @@ unsigned gpr_cpu_num_cores(void) {
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);
+ return (unsigned)GPR_HASH_POINTER(&magic_thread_local, gpr_cpu_num_cores());
}
#endif /* GPR_CPU_POSIX */