/work/workdir/UnpackedTarball/cairo/src/cairo-freed-pool-private.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* cairo - a vector graphics library with display and print output |
2 | | * |
3 | | * Copyright © 2009 Chris Wilson |
4 | | * |
5 | | * This library is free software; you can redistribute it and/or |
6 | | * modify it either under the terms of the GNU Lesser General Public |
7 | | * License version 2.1 as published by the Free Software Foundation |
8 | | * (the "LGPL") or, at your option, under the terms of the Mozilla |
9 | | * Public License Version 1.1 (the "MPL"). If you do not alter this |
10 | | * notice, a recipient may use your version of this file under either |
11 | | * the MPL or the LGPL. |
12 | | * |
13 | | * You should have received a copy of the LGPL along with this library |
14 | | * in the file COPYING-LGPL-2.1; if not, write to the Free Software |
15 | | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA |
16 | | * You should have received a copy of the MPL along with this library |
17 | | * in the file COPYING-MPL-1.1 |
18 | | * |
19 | | * The contents of this file are subject to the Mozilla Public License |
20 | | * Version 1.1 (the "License"); you may not use this file except in |
21 | | * compliance with the License. You may obtain a copy of the License at |
22 | | * http://www.mozilla.org/MPL/ |
23 | | * |
24 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY |
25 | | * OF ANY KIND, either express or implied. See the LGPL or the MPL for |
26 | | * the specific language governing rights and limitations. |
27 | | * |
28 | | * The Original Code is the cairo graphics library. |
29 | | * |
30 | | * The Initial Developer of the Original Code is University of Southern |
31 | | * California. |
32 | | * |
33 | | * Contributor(s): |
34 | | * Chris Wilson <chris@chris-wilson.co.uk> |
35 | | */ |
36 | | |
37 | | #ifndef CAIRO_FREED_POOL_H |
38 | | #define CAIRO_FREED_POOL_H |
39 | | |
40 | | #include "cairoint.h" |
41 | | #include "cairo-atomic-private.h" |
42 | | |
43 | | CAIRO_BEGIN_DECLS |
44 | | |
45 | | #define DISABLE_FREED_POOLS 0 |
46 | | |
47 | | #if HAS_ATOMIC_OPS && ! DISABLE_FREED_POOLS |
48 | | /* Keep a stash of recently freed clip_paths, since we need to |
49 | | * reallocate them frequently. |
50 | | */ |
51 | | #define MAX_FREED_POOL_SIZE 16 |
52 | | typedef struct { |
53 | | void *pool[MAX_FREED_POOL_SIZE]; |
54 | | cairo_atomic_int_t top; |
55 | | } freed_pool_t; |
56 | | |
57 | | static cairo_always_inline void * |
58 | | _atomic_fetch (void **slot) |
59 | 13.1M | { |
60 | 13.1M | void *ptr; |
61 | | |
62 | 13.1M | do { |
63 | 13.1M | ptr = _cairo_atomic_ptr_get (slot); |
64 | 13.1M | } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL)); |
65 | | |
66 | 13.1M | return ptr; |
67 | 13.1M | } cairo-pattern.c:_atomic_fetch Line | Count | Source | 59 | 3.44M | { | 60 | 3.44M | void *ptr; | 61 | | | 62 | 3.44M | do { | 63 | 3.44M | ptr = _cairo_atomic_ptr_get (slot); | 64 | 3.44M | } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL)); | 65 | | | 66 | 3.44M | return ptr; | 67 | 3.44M | } |
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_fetch cairo-clip.c:_atomic_fetch Line | Count | Source | 59 | 1.60M | { | 60 | 1.60M | void *ptr; | 61 | | | 62 | 1.60M | do { | 63 | 1.60M | ptr = _cairo_atomic_ptr_get (slot); | 64 | 1.60M | } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL)); | 65 | | | 66 | 1.60M | return ptr; | 67 | 1.60M | } |
cairo-default-context.c:_atomic_fetch Line | Count | Source | 59 | 8.13M | { | 60 | 8.13M | void *ptr; | 61 | | | 62 | 8.13M | do { | 63 | 8.13M | ptr = _cairo_atomic_ptr_get (slot); | 64 | 8.13M | } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL)); | 65 | | | 66 | 8.13M | return ptr; | 67 | 8.13M | } |
cairo-freed-pool.c:_atomic_fetch Line | Count | Source | 59 | 1.37k | { | 60 | 1.37k | void *ptr; | 61 | | | 62 | 1.37k | do { | 63 | 1.37k | ptr = _cairo_atomic_ptr_get (slot); | 64 | 1.37k | } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL)); | 65 | | | 66 | 1.37k | return ptr; | 67 | 1.37k | } |
Unexecuted instantiation: cairo-clip-polygon.c:_atomic_fetch Unexecuted instantiation: cairo-clip-region.c:_atomic_fetch Unexecuted instantiation: cairo-clip-surface.c:_atomic_fetch |
68 | | |
69 | | static cairo_always_inline cairo_bool_t |
70 | | _atomic_store (void **slot, void *ptr) |
71 | 13.1M | { |
72 | 13.1M | return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr); |
73 | 13.1M | } cairo-pattern.c:_atomic_store Line | Count | Source | 71 | 3.44M | { | 72 | 3.44M | return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr); | 73 | 3.44M | } |
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_store cairo-clip.c:_atomic_store Line | Count | Source | 71 | 1.60M | { | 72 | 1.60M | return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr); | 73 | 1.60M | } |
cairo-default-context.c:_atomic_store Line | Count | Source | 71 | 8.13M | { | 72 | 8.13M | return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr); | 73 | 8.13M | } |
Unexecuted instantiation: cairo-freed-pool.c:_atomic_store Unexecuted instantiation: cairo-clip-polygon.c:_atomic_store Unexecuted instantiation: cairo-clip-region.c:_atomic_store Unexecuted instantiation: cairo-clip-surface.c:_atomic_store |
74 | | |
75 | | cairo_private void * |
76 | | _freed_pool_get_search (freed_pool_t *pool); |
77 | | |
78 | | static inline void * |
79 | | _freed_pool_get (freed_pool_t *pool) |
80 | 13.1M | { |
81 | 13.1M | void *ptr; |
82 | 13.1M | int i; |
83 | | |
84 | 13.1M | i = _cairo_atomic_int_get_relaxed (&pool->top) - 1; |
85 | 13.1M | if (i < 0) |
86 | 86 | i = 0; |
87 | | |
88 | 13.1M | ptr = _atomic_fetch (&pool->pool[i]); |
89 | 13.1M | if (likely (ptr != NULL)) { |
90 | 13.1M | _cairo_atomic_int_set_relaxed (&pool->top, i); |
91 | 13.1M | return ptr; |
92 | 13.1M | } |
93 | | |
94 | | /* either empty or contended */ |
95 | 86 | return _freed_pool_get_search (pool); |
96 | 13.1M | } cairo-pattern.c:_freed_pool_get Line | Count | Source | 80 | 3.44M | { | 81 | 3.44M | void *ptr; | 82 | 3.44M | int i; | 83 | | | 84 | 3.44M | i = _cairo_atomic_int_get_relaxed (&pool->top) - 1; | 85 | 3.44M | if (i < 0) | 86 | 10 | i = 0; | 87 | | | 88 | 3.44M | ptr = _atomic_fetch (&pool->pool[i]); | 89 | 3.44M | if (likely (ptr != NULL)) { | 90 | 3.44M | _cairo_atomic_int_set_relaxed (&pool->top, i); | 91 | 3.44M | return ptr; | 92 | 3.44M | } | 93 | | | 94 | | /* either empty or contended */ | 95 | 10 | return _freed_pool_get_search (pool); | 96 | 3.44M | } |
Unexecuted instantiation: cairo-clip-boxes.c:_freed_pool_get cairo-clip.c:_freed_pool_get Line | Count | Source | 80 | 1.60M | { | 81 | 1.60M | void *ptr; | 82 | 1.60M | int i; | 83 | | | 84 | 1.60M | i = _cairo_atomic_int_get_relaxed (&pool->top) - 1; | 85 | 1.60M | if (i < 0) | 86 | 11 | i = 0; | 87 | | | 88 | 1.60M | ptr = _atomic_fetch (&pool->pool[i]); | 89 | 1.60M | if (likely (ptr != NULL)) { | 90 | 1.60M | _cairo_atomic_int_set_relaxed (&pool->top, i); | 91 | 1.60M | return ptr; | 92 | 1.60M | } | 93 | | | 94 | | /* either empty or contended */ | 95 | 11 | return _freed_pool_get_search (pool); | 96 | 1.60M | } |
cairo-default-context.c:_freed_pool_get Line | Count | Source | 80 | 8.13M | { | 81 | 8.13M | void *ptr; | 82 | 8.13M | int i; | 83 | | | 84 | 8.13M | i = _cairo_atomic_int_get_relaxed (&pool->top) - 1; | 85 | 8.13M | if (i < 0) | 86 | 65 | i = 0; | 87 | | | 88 | 8.13M | ptr = _atomic_fetch (&pool->pool[i]); | 89 | 8.13M | if (likely (ptr != NULL)) { | 90 | 8.13M | _cairo_atomic_int_set_relaxed (&pool->top, i); | 91 | 8.13M | return ptr; | 92 | 8.13M | } | 93 | | | 94 | | /* either empty or contended */ | 95 | 65 | return _freed_pool_get_search (pool); | 96 | 8.13M | } |
Unexecuted instantiation: cairo-freed-pool.c:_freed_pool_get Unexecuted instantiation: cairo-clip-polygon.c:_freed_pool_get Unexecuted instantiation: cairo-clip-region.c:_freed_pool_get Unexecuted instantiation: cairo-clip-surface.c:_freed_pool_get |
97 | | |
98 | | cairo_private void |
99 | | _freed_pool_put_search (freed_pool_t *pool, void *ptr); |
100 | | |
101 | | static inline void |
102 | | _freed_pool_put (freed_pool_t *pool, void *ptr) |
103 | 13.1M | { |
104 | 13.1M | int i; |
105 | | |
106 | 13.1M | i = _cairo_atomic_int_get_relaxed (&pool->top); |
107 | 13.1M | if (likely (i < ARRAY_LENGTH (pool->pool) && |
108 | 13.1M | _atomic_store (&pool->pool[i], ptr))) |
109 | 13.1M | { |
110 | 13.1M | _cairo_atomic_int_set_relaxed (&pool->top, i + 1); |
111 | 13.1M | return; |
112 | 13.1M | } |
113 | | |
114 | | /* either full or contended */ |
115 | 0 | _freed_pool_put_search (pool, ptr); |
116 | 0 | } cairo-pattern.c:_freed_pool_put Line | Count | Source | 103 | 3.44M | { | 104 | 3.44M | int i; | 105 | | | 106 | 3.44M | i = _cairo_atomic_int_get_relaxed (&pool->top); | 107 | 3.44M | if (likely (i < ARRAY_LENGTH (pool->pool) && | 108 | 3.44M | _atomic_store (&pool->pool[i], ptr))) | 109 | 3.44M | { | 110 | 3.44M | _cairo_atomic_int_set_relaxed (&pool->top, i + 1); | 111 | 3.44M | return; | 112 | 3.44M | } | 113 | | | 114 | | /* either full or contended */ | 115 | 0 | _freed_pool_put_search (pool, ptr); | 116 | 0 | } |
Unexecuted instantiation: cairo-clip-boxes.c:_freed_pool_put cairo-clip.c:_freed_pool_put Line | Count | Source | 103 | 1.60M | { | 104 | 1.60M | int i; | 105 | | | 106 | 1.60M | i = _cairo_atomic_int_get_relaxed (&pool->top); | 107 | 1.60M | if (likely (i < ARRAY_LENGTH (pool->pool) && | 108 | 1.60M | _atomic_store (&pool->pool[i], ptr))) | 109 | 1.60M | { | 110 | 1.60M | _cairo_atomic_int_set_relaxed (&pool->top, i + 1); | 111 | 1.60M | return; | 112 | 1.60M | } | 113 | | | 114 | | /* either full or contended */ | 115 | 0 | _freed_pool_put_search (pool, ptr); | 116 | 0 | } |
cairo-default-context.c:_freed_pool_put Line | Count | Source | 103 | 8.13M | { | 104 | 8.13M | int i; | 105 | | | 106 | 8.13M | i = _cairo_atomic_int_get_relaxed (&pool->top); | 107 | 8.13M | if (likely (i < ARRAY_LENGTH (pool->pool) && | 108 | 8.13M | _atomic_store (&pool->pool[i], ptr))) | 109 | 8.13M | { | 110 | 8.13M | _cairo_atomic_int_set_relaxed (&pool->top, i + 1); | 111 | 8.13M | return; | 112 | 8.13M | } | 113 | | | 114 | | /* either full or contended */ | 115 | 0 | _freed_pool_put_search (pool, ptr); | 116 | 0 | } |
Unexecuted instantiation: cairo-freed-pool.c:_freed_pool_put Unexecuted instantiation: cairo-clip-polygon.c:_freed_pool_put Unexecuted instantiation: cairo-clip-region.c:_freed_pool_put Unexecuted instantiation: cairo-clip-surface.c:_freed_pool_put |
117 | | |
118 | | cairo_private void |
119 | | _freed_pool_reset (freed_pool_t *pool); |
120 | | |
121 | | #define HAS_FREED_POOL 1 |
122 | | |
123 | | #else |
124 | | |
125 | | /* A warning about an unused freed-pool in a build without atomics |
126 | | * enabled usually indicates a missing _freed_pool_reset() in the |
127 | | * static reset function */ |
128 | | |
129 | | typedef int freed_pool_t; |
130 | | |
131 | | #define _freed_pool_get(pool) NULL |
132 | | #define _freed_pool_put(pool, ptr) free(ptr) |
133 | | #define _freed_pool_reset(ptr) |
134 | | |
135 | | #endif |
136 | | |
137 | | CAIRO_END_DECLS |
138 | | |
139 | | #endif /* CAIRO_FREED_POOL_PRIVATE_H */ |