| Index: third_party/grpc/src/core/transport/chttp2/varint.c
|
| diff --git a/third_party/tcmalloc/vendor/src/base/spinlock_posix-inl.h b/third_party/grpc/src/core/transport/chttp2/varint.c
|
| similarity index 62%
|
| copy from third_party/tcmalloc/vendor/src/base/spinlock_posix-inl.h
|
| copy to third_party/grpc/src/core/transport/chttp2/varint.c
|
| index e1d43b7db29fb7076d7d4b2012ea309bc05c7fdc..1cc235e9899ec7c095fc0cbaa3bfe7a6ce46271f 100644
|
| --- a/third_party/tcmalloc/vendor/src/base/spinlock_posix-inl.h
|
| +++ b/third_party/grpc/src/core/transport/chttp2/varint.c
|
| @@ -1,10 +1,12 @@
|
| -/* Copyright (c) 2009, Google Inc.
|
| +/*
|
| + *
|
| + * Copyright 2015, 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
|
| @@ -14,7 +16,7 @@
|
| * * 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
|
| @@ -27,36 +29,37 @@
|
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| *
|
| - * ---
|
| - * This file is a Posix-specific part of spinlock_internal.cc
|
| */
|
|
|
| -#include <config.h>
|
| -#include <errno.h>
|
| -#ifdef HAVE_SCHED_H
|
| -#include <sched.h> /* For sched_yield() */
|
| -#endif
|
| -#include <time.h> /* For nanosleep() */
|
| +#include "src/core/transport/chttp2/varint.h"
|
|
|
| -namespace base {
|
| -namespace internal {
|
| -
|
| -void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop) {
|
| - int save_errno = errno;
|
| - if (loop == 0) {
|
| - } else if (loop == 1) {
|
| - sched_yield();
|
| +uint32_t grpc_chttp2_hpack_varint_length(uint32_t tail_value) {
|
| + if (tail_value < (1 << 7)) {
|
| + return 2;
|
| + } else if (tail_value < (1 << 14)) {
|
| + return 3;
|
| + } else if (tail_value < (1 << 21)) {
|
| + return 4;
|
| + } else if (tail_value < (1 << 28)) {
|
| + return 5;
|
| } else {
|
| - struct timespec tm;
|
| - tm.tv_sec = 0;
|
| - tm.tv_nsec = base::internal::SuggestedDelayNS(loop);
|
| - nanosleep(&tm, NULL);
|
| + return 6;
|
| }
|
| - errno = save_errno;
|
| }
|
|
|
| -void SpinLockWake(volatile Atomic32 *w, bool all) {
|
| +void grpc_chttp2_hpack_write_varint_tail(uint32_t tail_value, uint8_t* target,
|
| + uint32_t tail_length) {
|
| + switch (tail_length) {
|
| + case 5:
|
| + target[4] = (uint8_t)((tail_value >> 28) | 0x80);
|
| + case 4:
|
| + target[3] = (uint8_t)((tail_value >> 21) | 0x80);
|
| + case 3:
|
| + target[2] = (uint8_t)((tail_value >> 14) | 0x80);
|
| + case 2:
|
| + target[1] = (uint8_t)((tail_value >> 7) | 0x80);
|
| + case 1:
|
| + target[0] = (uint8_t)((tail_value) | 0x80);
|
| + }
|
| + target[tail_length - 1] &= 0x7f;
|
| }
|
| -
|
| -} // namespace internal
|
| -} // namespace base
|
|
|