Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/workdir/UnpackedTarball/cairo/src/cairo-freed-pool-private.h
Line
Count
Source
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
    cairo_atomic_intptr_t 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 (cairo_atomic_intptr_t *slot)
59
20.2M
{
60
20.2M
    void *ptr;
61
62
20.2M
    do {
63
20.2M
        ptr = _cairo_atomic_ptr_get (slot);
64
20.2M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
20.2M
    return ptr;
67
20.2M
}
cairo-pattern.c:_atomic_fetch
Line
Count
Source
59
3.88M
{
60
3.88M
    void *ptr;
61
62
3.88M
    do {
63
3.88M
        ptr = _cairo_atomic_ptr_get (slot);
64
3.88M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
3.88M
    return ptr;
67
3.88M
}
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_fetch
cairo-clip.c:_atomic_fetch
Line
Count
Source
59
5.89M
{
60
5.89M
    void *ptr;
61
62
5.89M
    do {
63
5.89M
        ptr = _cairo_atomic_ptr_get (slot);
64
5.89M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
5.89M
    return ptr;
67
5.89M
}
cairo-default-context.c:_atomic_fetch
Line
Count
Source
59
10.4M
{
60
10.4M
    void *ptr;
61
62
10.4M
    do {
63
10.4M
        ptr = _cairo_atomic_ptr_get (slot);
64
10.4M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
10.4M
    return ptr;
67
10.4M
}
cairo-freed-pool.c:_atomic_fetch
Line
Count
Source
59
2.25k
{
60
2.25k
    void *ptr;
61
62
2.25k
    do {
63
2.25k
        ptr = _cairo_atomic_ptr_get (slot);
64
2.25k
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
2.25k
    return ptr;
67
2.25k
}
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 (cairo_atomic_intptr_t *slot, void *ptr)
71
20.2M
{
72
20.2M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
20.2M
}
cairo-pattern.c:_atomic_store
Line
Count
Source
71
3.88M
{
72
3.88M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
3.88M
}
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_store
cairo-clip.c:_atomic_store
Line
Count
Source
71
5.89M
{
72
5.89M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
5.89M
}
cairo-default-context.c:_atomic_store
Line
Count
Source
71
10.4M
{
72
10.4M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
10.4M
}
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
20.2M
{
81
20.2M
    void *ptr;
82
20.2M
    int i;
83
84
20.2M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
20.2M
    if (i < 0)
86
141
  i = 0;
87
88
20.2M
    ptr = _atomic_fetch (&pool->pool[i]);
89
20.2M
    if (likely (ptr != NULL)) {
90
20.2M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
20.2M
  return ptr;
92
20.2M
    }
93
94
    /* either empty or contended */
95
141
    return _freed_pool_get_search (pool);
96
20.2M
}
cairo-pattern.c:_freed_pool_get
Line
Count
Source
80
3.88M
{
81
3.88M
    void *ptr;
82
3.88M
    int i;
83
84
3.88M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
3.88M
    if (i < 0)
86
10
  i = 0;
87
88
3.88M
    ptr = _atomic_fetch (&pool->pool[i]);
89
3.88M
    if (likely (ptr != NULL)) {
90
3.88M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
3.88M
  return ptr;
92
3.88M
    }
93
94
    /* either empty or contended */
95
10
    return _freed_pool_get_search (pool);
96
3.88M
}
Unexecuted instantiation: cairo-clip-boxes.c:_freed_pool_get
cairo-clip.c:_freed_pool_get
Line
Count
Source
80
5.89M
{
81
5.89M
    void *ptr;
82
5.89M
    int i;
83
84
5.89M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
5.89M
    if (i < 0)
86
37
  i = 0;
87
88
5.89M
    ptr = _atomic_fetch (&pool->pool[i]);
89
5.89M
    if (likely (ptr != NULL)) {
90
5.89M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
5.89M
  return ptr;
92
5.89M
    }
93
94
    /* either empty or contended */
95
37
    return _freed_pool_get_search (pool);
96
5.89M
}
cairo-default-context.c:_freed_pool_get
Line
Count
Source
80
10.4M
{
81
10.4M
    void *ptr;
82
10.4M
    int i;
83
84
10.4M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
10.4M
    if (i < 0)
86
94
  i = 0;
87
88
10.4M
    ptr = _atomic_fetch (&pool->pool[i]);
89
10.4M
    if (likely (ptr != NULL)) {
90
10.4M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
10.4M
  return ptr;
92
10.4M
    }
93
94
    /* either empty or contended */
95
94
    return _freed_pool_get_search (pool);
96
10.4M
}
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
20.2M
{
104
20.2M
    int i;
105
106
20.2M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
20.2M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
20.2M
    _atomic_store (&pool->pool[i], ptr)))
109
20.2M
    {
110
20.2M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
20.2M
  return;
112
20.2M
    }
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.88M
{
104
3.88M
    int i;
105
106
3.88M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
3.88M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
3.88M
    _atomic_store (&pool->pool[i], ptr)))
109
3.88M
    {
110
3.88M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
3.88M
  return;
112
3.88M
    }
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
5.89M
{
104
5.89M
    int i;
105
106
5.89M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
5.89M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
5.89M
    _atomic_store (&pool->pool[i], ptr)))
109
5.89M
    {
110
5.89M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
5.89M
  return;
112
5.89M
    }
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
10.4M
{
104
10.4M
    int i;
105
106
10.4M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
10.4M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
10.4M
    _atomic_store (&pool->pool[i], ptr)))
109
10.4M
    {
110
10.4M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
10.4M
  return;
112
10.4M
    }
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 */