Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: third_party/grpc/src/core/support/alloc.c

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
3 * 5 *
4 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
6 * met: 8 * met:
7 * 9 *
8 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 12 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 13 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 14 * in the documentation and/or other materials provided with the
13 * distribution. 15 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 16 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 17 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 18 * this software without specific prior written permission.
17 * 19 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
29 */ 32 */
30 33
31 #ifndef SVGUnknownElement_h 34 #include <grpc/support/alloc.h>
32 #define SVGUnknownElement_h
33 35
34 #include "core/svg/SVGElement.h" 36 #include <stdlib.h>
37 #include <grpc/support/log.h>
38 #include <grpc/support/port_platform.h>
39 #include "src/core/profiling/timers.h"
35 40
36 namespace blink { 41 static gpr_allocation_functions g_alloc_functions = {malloc, realloc, free};
37 42
38 // This type is used for 2 kinds of elements: 43 gpr_allocation_functions gpr_get_allocation_functions() {
39 // - Unknown Elements in SVG namespace 44 return g_alloc_functions;
40 // - Registered custom tag elements in SVG namespace (http://www.w3.org/TR/2013/ WD-custom-elements-20130514/#registering-custom-elements) 45 }
41 //
42 // The main purpose of this class at the moment is to override layoutObjectIsNee ded() to return
43 // false to make sure we don't attempt to layout such elements.
44 class SVGUnknownElement final : public SVGElement {
45 public:
46 DECLARE_ELEMENT_FACTORY_WITH_TAGNAME(SVGUnknownElement);
47 46
48 private: 47 void gpr_set_allocation_functions(gpr_allocation_functions functions) {
49 SVGUnknownElement(const QualifiedName&, Document&); 48 GPR_ASSERT(functions.malloc_fn != NULL);
49 GPR_ASSERT(functions.realloc_fn != NULL);
50 GPR_ASSERT(functions.free_fn != NULL);
51 g_alloc_functions = functions;
52 }
50 53
51 bool layoutObjectIsNeeded(const ComputedStyle&) override { return false; } 54 void *gpr_malloc(size_t size) {
52 }; 55 void *p;
56 GPR_TIMER_BEGIN("gpr_malloc", 0);
57 p = g_alloc_functions.malloc_fn(size);
58 if (!p) {
59 abort();
60 }
61 GPR_TIMER_END("gpr_malloc", 0);
62 return p;
63 }
53 64
54 } // namespace blink 65 void gpr_free(void *p) {
66 GPR_TIMER_BEGIN("gpr_free", 0);
67 g_alloc_functions.free_fn(p);
68 GPR_TIMER_END("gpr_free", 0);
69 }
55 70
56 #endif // SVGUnknownElement_h 71 void *gpr_realloc(void *p, size_t size) {
72 GPR_TIMER_BEGIN("gpr_realloc", 0);
73 p = g_alloc_functions.realloc_fn(p, size);
74 if (!p) {
75 abort();
76 }
77 GPR_TIMER_END("gpr_realloc", 0);
78 return p;
79 }
80
81 void *gpr_malloc_aligned(size_t size, size_t alignment_log) {
82 size_t alignment = ((size_t)1) << alignment_log;
83 size_t extra = alignment - 1 + sizeof(void *);
84 void *p = gpr_malloc(size + extra);
85 void **ret = (void **)(((uintptr_t)p + extra) & ~(alignment - 1));
86 ret[-1] = p;
87 return (void *)ret;
88 }
89
90 void gpr_free_aligned(void *ptr) { free(((void **)ptr)[-1]); }
OLDNEW
« no previous file with comments | « third_party/grpc/src/core/statistics/window_stats.c ('k') | third_party/grpc/src/core/support/avl.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698