diff --git a/src/cairo-freed-pool-private.h b/src/cairo-freed-pool-private.h index 0ec6de3..b5ced1a 100644 --- a/src/cairo-freed-pool-private.h +++ b/src/cairo-freed-pool-private.h @@ -45,13 +45,15 @@ CAIRO_BEGIN_DECLS #define DISABLE_FREED_POOLS 0 #if HAS_ATOMIC_OPS && ! DISABLE_FREED_POOLS +#include + /* Keep a stash of recently freed clip_paths, since we need to * reallocate them frequently. */ #define MAX_FREED_POOL_SIZE 16 typedef struct { void *pool[MAX_FREED_POOL_SIZE]; - int top; + _Atomic int top; } freed_pool_t; static cairo_always_inline void * @@ -81,13 +83,13 @@ _freed_pool_get (freed_pool_t *pool) void *ptr; int i; - i = pool->top - 1; + i = atomic_load_explicit(&pool->top, memory_order_relaxed) - 1; if (i < 0) i = 0; ptr = _atomic_fetch (&pool->pool[i]); if (likely (ptr != NULL)) { - pool->top = i; + atomic_store_explicit(&pool->top, i, memory_order_relaxed); return ptr; } @@ -103,11 +105,11 @@ _freed_pool_put (freed_pool_t *pool, void *ptr) { int i; - i = pool->top; + i = atomic_load_explicit(&pool->top, memory_order_relaxed); if (likely (i < ARRAY_LENGTH (pool->pool) && _atomic_store (&pool->pool[i], ptr))) { - pool->top = i + 1; + atomic_store_explicit(&pool->top, i + 1, memory_order_relaxed); return; } diff --git a/src/cairo-freed-pool.c b/src/cairo-freed-pool.c index cfdc8e9..0228c77 100644 --- a/src/cairo-freed-pool.c +++ b/src/cairo-freed-pool.c @@ -50,13 +50,13 @@ _freed_pool_get_search (freed_pool_t *pool) for (i = ARRAY_LENGTH (pool->pool); i--;) { ptr = _atomic_fetch (&pool->pool[i]); if (ptr != NULL) { - pool->top = i; + atomic_store_explicit(&pool->top, i, memory_order_relaxed); return ptr; } } /* empty */ - pool->top = 0; + atomic_store_explicit(&pool->top, 0, memory_order_relaxed); return NULL; } @@ -67,13 +67,13 @@ _freed_pool_put_search (freed_pool_t *pool, void *ptr) for (i = 0; i < ARRAY_LENGTH (pool->pool); i++) { if (_atomic_store (&pool->pool[i], ptr)) { - pool->top = i + 1; + atomic_store_explicit(&pool->top, i + 1, memory_order_relaxed); return; } } /* full */ - pool->top = i; + atomic_store_explicit(&pool->top, i, memory_order_relaxed); free (ptr); } @@ -87,7 +87,7 @@ _freed_pool_reset (freed_pool_t *pool) pool->pool[i] = NULL; } - pool->top = 0; + atomic_store_explicit(&pool->top, 0, memory_order_relaxed); } #endif