| Index: third_party/grpc/test/core/support/tls_test.c
|
| diff --git a/third_party/WebKit/Source/platform/exported/WebData.cpp b/third_party/grpc/test/core/support/tls_test.c
|
| similarity index 59%
|
| copy from third_party/WebKit/Source/platform/exported/WebData.cpp
|
| copy to third_party/grpc/test/core/support/tls_test.c
|
| index b29b83e6410a9f00c829a60e0169d2127fa21b7e..c6fb1a4a2606296ea66bd85299151ea36ee54d4a 100644
|
| --- a/third_party/WebKit/Source/platform/exported/WebData.cpp
|
| +++ b/third_party/grpc/test/core/support/tls_test.c
|
| @@ -1,5 +1,7 @@
|
| /*
|
| - * Copyright (C) 2009 Google Inc. All rights reserved.
|
| + *
|
| + * 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
|
| @@ -26,57 +28,56 @@
|
| * 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.
|
| + *
|
| */
|
|
|
| -#include "public/platform/WebData.h"
|
| +/* Test of gpr thread local storage support. */
|
|
|
| -#include "platform/SharedBuffer.h"
|
| +#include <stdio.h>
|
| +#include <stdlib.h>
|
| +#include <grpc/support/log.h>
|
| +#include <grpc/support/sync.h>
|
| +#include <grpc/support/thd.h>
|
| +#include <grpc/support/tls.h>
|
| +#include "test/core/util/test_config.h"
|
|
|
| -namespace blink {
|
| +#define NUM_THREADS 100
|
|
|
| -void WebData::reset()
|
| -{
|
| - m_private.reset();
|
| -}
|
| +GPR_TLS_DECL(test_var);
|
|
|
| -void WebData::assign(const WebData& other)
|
| -{
|
| - m_private = other.m_private;
|
| -}
|
| +static void thd_body(void *arg) {
|
| + intptr_t i;
|
|
|
| -void WebData::assign(const char* data, size_t size)
|
| -{
|
| - m_private = SharedBuffer::create(data, size);
|
| -}
|
| + GPR_ASSERT(gpr_tls_get(&test_var) == 0);
|
|
|
| -size_t WebData::size() const
|
| -{
|
| - if (m_private.isNull())
|
| - return 0;
|
| - return m_private->size();
|
| + for (i = 0; i < 10000000; i++) {
|
| + gpr_tls_set(&test_var, i);
|
| + GPR_ASSERT(gpr_tls_get(&test_var) == i);
|
| + }
|
| + gpr_tls_set(&test_var, 0);
|
| }
|
|
|
| -const char* WebData::data() const
|
| -{
|
| - if (m_private.isNull())
|
| - return 0;
|
| - return m_private->data();
|
| -}
|
| +/* ------------------------------------------------- */
|
|
|
| -WebData::WebData(const PassRefPtr<SharedBuffer>& buffer)
|
| - : m_private(buffer)
|
| -{
|
| -}
|
| +int main(int argc, char *argv[]) {
|
| + gpr_thd_options opt = gpr_thd_options_default();
|
| + int i;
|
| + gpr_thd_id threads[NUM_THREADS];
|
|
|
| -WebData& WebData::operator=(const PassRefPtr<SharedBuffer>& buffer)
|
| -{
|
| - m_private = buffer;
|
| - return *this;
|
| -}
|
| + grpc_test_init(argc, argv);
|
|
|
| -WebData::operator PassRefPtr<SharedBuffer>() const
|
| -{
|
| - return PassRefPtr<SharedBuffer>(m_private.get());
|
| -}
|
| + gpr_tls_init(&test_var);
|
| +
|
| + gpr_thd_options_set_joinable(&opt);
|
|
|
| -} // namespace blink
|
| + for (i = 0; i < NUM_THREADS; i++) {
|
| + gpr_thd_new(&threads[i], thd_body, NULL, &opt);
|
| + }
|
| + for (i = 0; i < NUM_THREADS; i++) {
|
| + gpr_thd_join(threads[i]);
|
| + }
|
| +
|
| + gpr_tls_destroy(&test_var);
|
| +
|
| + return 0;
|
| +}
|
|
|