Coverage Report

Created: 2026-09-28 08:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/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
8.12M
{
60
8.12M
    void *ptr;
61
62
8.12M
    do {
63
8.12M
        ptr = _cairo_atomic_ptr_get (slot);
64
8.12M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
8.12M
    return ptr;
67
8.12M
}
cairo-pattern.c:_atomic_fetch
Line
Count
Source
59
297k
{
60
297k
    void *ptr;
61
62
297k
    do {
63
297k
        ptr = _cairo_atomic_ptr_get (slot);
64
297k
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
297k
    return ptr;
67
297k
}
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_fetch
cairo-clip.c:_atomic_fetch
Line
Count
Source
59
7.36M
{
60
7.36M
    void *ptr;
61
62
7.36M
    do {
63
7.36M
        ptr = _cairo_atomic_ptr_get (slot);
64
7.36M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
7.36M
    return ptr;
67
7.36M
}
cairo-default-context.c:_atomic_fetch
Line
Count
Source
59
17.4k
{
60
17.4k
    void *ptr;
61
62
17.4k
    do {
63
17.4k
        ptr = _cairo_atomic_ptr_get (slot);
64
17.4k
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
17.4k
    return ptr;
67
17.4k
}
cairo-freed-pool.c:_atomic_fetch
Line
Count
Source
59
441k
{
60
441k
    void *ptr;
61
62
441k
    do {
63
441k
        ptr = _cairo_atomic_ptr_get (slot);
64
441k
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
441k
    return ptr;
67
441k
}
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
8.15M
{
72
8.15M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
8.15M
}
cairo-pattern.c:_atomic_store
Line
Count
Source
71
296k
{
72
296k
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
296k
}
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_store
cairo-clip.c:_atomic_store
Line
Count
Source
71
7.34M
{
72
7.34M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
7.34M
}
cairo-default-context.c:_atomic_store
Line
Count
Source
71
17.3k
{
72
17.3k
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
17.3k
}
cairo-freed-pool.c:_atomic_store
Line
Count
Source
71
495k
{
72
495k
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
495k
}
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
7.68M
{
81
7.68M
    void *ptr;
82
7.68M
    int i;
83
84
7.68M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
7.68M
    if (i < 0)
86
27.6k
  i = 0;
87
88
7.68M
    ptr = _atomic_fetch (&pool->pool[i]);
89
7.68M
    if (likely (ptr != NULL)) {
90
7.65M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
7.65M
  return ptr;
92
7.65M
    }
93
94
    /* either empty or contended */
95
27.6k
    return _freed_pool_get_search (pool);
96
7.68M
}
cairo-pattern.c:_freed_pool_get
Line
Count
Source
80
297k
{
81
297k
    void *ptr;
82
297k
    int i;
83
84
297k
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
297k
    if (i < 0)
86
747
  i = 0;
87
88
297k
    ptr = _atomic_fetch (&pool->pool[i]);
89
297k
    if (likely (ptr != NULL)) {
90
296k
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
296k
  return ptr;
92
296k
    }
93
94
    /* either empty or contended */
95
747
    return _freed_pool_get_search (pool);
96
297k
}
Unexecuted instantiation: cairo-clip-boxes.c:_freed_pool_get
cairo-clip.c:_freed_pool_get
Line
Count
Source
80
7.36M
{
81
7.36M
    void *ptr;
82
7.36M
    int i;
83
84
7.36M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
7.36M
    if (i < 0)
86
26.7k
  i = 0;
87
88
7.36M
    ptr = _atomic_fetch (&pool->pool[i]);
89
7.36M
    if (likely (ptr != NULL)) {
90
7.34M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
7.34M
  return ptr;
92
7.34M
    }
93
94
    /* either empty or contended */
95
26.7k
    return _freed_pool_get_search (pool);
96
7.36M
}
cairo-default-context.c:_freed_pool_get
Line
Count
Source
80
17.4k
{
81
17.4k
    void *ptr;
82
17.4k
    int i;
83
84
17.4k
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
17.4k
    if (i < 0)
86
66
  i = 0;
87
88
17.4k
    ptr = _atomic_fetch (&pool->pool[i]);
89
17.4k
    if (likely (ptr != NULL)) {
90
17.3k
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
17.3k
  return ptr;
92
17.3k
    }
93
94
    /* either empty or contended */
95
66
    return _freed_pool_get_search (pool);
96
17.4k
}
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
7.68M
{
104
7.68M
    int i;
105
106
7.68M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
7.68M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
7.68M
    _atomic_store (&pool->pool[i], ptr)))
109
7.65M
    {
110
7.65M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
7.65M
  return;
112
7.65M
    }
113
114
    /* either full or contended */
115
30.9k
    _freed_pool_put_search (pool, ptr);
116
30.9k
}
cairo-pattern.c:_freed_pool_put
Line
Count
Source
103
300k
{
104
300k
    int i;
105
106
300k
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
300k
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
300k
    _atomic_store (&pool->pool[i], ptr)))
109
296k
    {
110
296k
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
296k
  return;
112
296k
    }
113
114
    /* either full or contended */
115
4.18k
    _freed_pool_put_search (pool, ptr);
116
4.18k
}
Unexecuted instantiation: cairo-clip-boxes.c:_freed_pool_put
cairo-clip.c:_freed_pool_put
Line
Count
Source
103
7.36M
{
104
7.36M
    int i;
105
106
7.36M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
7.36M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
7.36M
    _atomic_store (&pool->pool[i], ptr)))
109
7.34M
    {
110
7.34M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
7.34M
  return;
112
7.34M
    }
113
114
    /* either full or contended */
115
26.7k
    _freed_pool_put_search (pool, ptr);
116
26.7k
}
cairo-default-context.c:_freed_pool_put
Line
Count
Source
103
17.4k
{
104
17.4k
    int i;
105
106
17.4k
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
17.4k
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
17.4k
    _atomic_store (&pool->pool[i], ptr)))
109
17.3k
    {
110
17.3k
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
17.3k
  return;
112
17.3k
    }
113
114
    /* either full or contended */
115
38
    _freed_pool_put_search (pool, ptr);
116
38
}
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 */