Coverage Report

Created: 2025-11-16 09:57

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