Coverage Report

Created: 2026-10-14 09:33

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