Coverage Report

Created: 2026-09-28 10:59

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
4.48M
{
60
4.48M
    void *ptr;
61
62
4.48M
    do {
63
4.48M
        ptr = _cairo_atomic_ptr_get (slot);
64
4.48M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
4.48M
    return ptr;
67
4.48M
}
cairo-pattern.c:_atomic_fetch
Line
Count
Source
59
793k
{
60
793k
    void *ptr;
61
62
793k
    do {
63
793k
        ptr = _cairo_atomic_ptr_get (slot);
64
793k
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
793k
    return ptr;
67
793k
}
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_fetch
cairo-clip.c:_atomic_fetch
Line
Count
Source
59
1.84M
{
60
1.84M
    void *ptr;
61
62
1.84M
    do {
63
1.84M
        ptr = _cairo_atomic_ptr_get (slot);
64
1.84M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
1.84M
    return ptr;
67
1.84M
}
cairo-default-context.c:_atomic_fetch
Line
Count
Source
59
1.84M
{
60
1.84M
    void *ptr;
61
62
1.84M
    do {
63
1.84M
        ptr = _cairo_atomic_ptr_get (slot);
64
1.84M
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
1.84M
    return ptr;
67
1.84M
}
cairo-freed-pool.c:_atomic_fetch
Line
Count
Source
59
1.87k
{
60
1.87k
    void *ptr;
61
62
1.87k
    do {
63
1.87k
        ptr = _cairo_atomic_ptr_get (slot);
64
1.87k
    } while (! _cairo_atomic_ptr_cmpxchg (slot, ptr, NULL));
65
66
1.87k
    return ptr;
67
1.87k
}
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
4.48M
{
72
4.48M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
4.48M
}
cairo-pattern.c:_atomic_store
Line
Count
Source
71
793k
{
72
793k
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
793k
}
Unexecuted instantiation: cairo-clip-boxes.c:_atomic_store
cairo-clip.c:_atomic_store
Line
Count
Source
71
1.84M
{
72
1.84M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
1.84M
}
cairo-default-context.c:_atomic_store
Line
Count
Source
71
1.84M
{
72
1.84M
    return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr);
73
1.84M
}
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
4.48M
{
81
4.48M
    void *ptr;
82
4.48M
    int i;
83
84
4.48M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
4.48M
    if (i < 0)
86
117
  i = 0;
87
88
4.48M
    ptr = _atomic_fetch (&pool->pool[i]);
89
4.48M
    if (likely (ptr != NULL)) {
90
4.48M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
4.48M
  return ptr;
92
4.48M
    }
93
94
    /* either empty or contended */
95
117
    return _freed_pool_get_search (pool);
96
4.48M
}
cairo-pattern.c:_freed_pool_get
Line
Count
Source
80
793k
{
81
793k
    void *ptr;
82
793k
    int i;
83
84
793k
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
793k
    if (i < 0)
86
6
  i = 0;
87
88
793k
    ptr = _atomic_fetch (&pool->pool[i]);
89
793k
    if (likely (ptr != NULL)) {
90
793k
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
793k
  return ptr;
92
793k
    }
93
94
    /* either empty or contended */
95
6
    return _freed_pool_get_search (pool);
96
793k
}
Unexecuted instantiation: cairo-clip-boxes.c:_freed_pool_get
cairo-clip.c:_freed_pool_get
Line
Count
Source
80
1.84M
{
81
1.84M
    void *ptr;
82
1.84M
    int i;
83
84
1.84M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
1.84M
    if (i < 0)
86
29
  i = 0;
87
88
1.84M
    ptr = _atomic_fetch (&pool->pool[i]);
89
1.84M
    if (likely (ptr != NULL)) {
90
1.84M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
1.84M
  return ptr;
92
1.84M
    }
93
94
    /* either empty or contended */
95
29
    return _freed_pool_get_search (pool);
96
1.84M
}
cairo-default-context.c:_freed_pool_get
Line
Count
Source
80
1.84M
{
81
1.84M
    void *ptr;
82
1.84M
    int i;
83
84
1.84M
    i = _cairo_atomic_int_get_relaxed (&pool->top) - 1;
85
1.84M
    if (i < 0)
86
82
  i = 0;
87
88
1.84M
    ptr = _atomic_fetch (&pool->pool[i]);
89
1.84M
    if (likely (ptr != NULL)) {
90
1.84M
  _cairo_atomic_int_set_relaxed (&pool->top, i);
91
1.84M
  return ptr;
92
1.84M
    }
93
94
    /* either empty or contended */
95
82
    return _freed_pool_get_search (pool);
96
1.84M
}
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
4.48M
{
104
4.48M
    int i;
105
106
4.48M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
4.48M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
4.48M
    _atomic_store (&pool->pool[i], ptr)))
109
4.48M
    {
110
4.48M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
4.48M
  return;
112
4.48M
    }
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
793k
{
104
793k
    int i;
105
106
793k
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
793k
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
793k
    _atomic_store (&pool->pool[i], ptr)))
109
793k
    {
110
793k
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
793k
  return;
112
793k
    }
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.84M
{
104
1.84M
    int i;
105
106
1.84M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
1.84M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
1.84M
    _atomic_store (&pool->pool[i], ptr)))
109
1.84M
    {
110
1.84M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
1.84M
  return;
112
1.84M
    }
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
1.84M
{
104
1.84M
    int i;
105
106
1.84M
    i = _cairo_atomic_int_get_relaxed (&pool->top);
107
1.84M
    if (likely (i < ARRAY_LENGTH (pool->pool) &&
108
1.84M
    _atomic_store (&pool->pool[i], ptr)))
109
1.84M
    {
110
1.84M
  _cairo_atomic_int_set_relaxed (&pool->top, i + 1);
111
1.84M
  return;
112
1.84M
    }
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 */