summaryrefslogtreecommitdiff
path: root/src/cairo-clip.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2010-01-19 18:06:54 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2010-01-22 23:01:50 +0000
commitf2c32d01836379766bc287edf77381123767daeb (patch)
tree8dad46d932b1e80ce81cd1eec8b38913974e4125 /src/cairo-clip.c
parentcfd204824fada7d2b4bcf4994c4200ae9b5a8b26 (diff)
Unify the two freed object pools
Discard some duplicate code and shared a single freed object pointer pool between the pattern and clip.
Diffstat (limited to 'src/cairo-clip.c')
-rw-r--r--src/cairo-clip.c88
1 files changed, 3 insertions, 85 deletions
diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 2a50385f..b3d30341 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -42,95 +42,13 @@
#include "cairoint.h"
#include "cairo-clip-private.h"
#include "cairo-error-private.h"
+#include "cairo-freed-pool-private.h"
#include "cairo-path-fixed-private.h"
#include "cairo-region-private.h"
-/* Keep a stash of recently freed clip_paths, since we need to
- * reallocate them frequently.
- */
-#define MAX_FREED_POOL_SIZE 4
-typedef struct {
- void *pool[MAX_FREED_POOL_SIZE];
- int top;
-} freed_pool_t;
-
+#if HAS_FREED_POOL
static freed_pool_t clip_path_pool;
-
-static void *
-_atomic_fetch (void **slot)
-{
- return _cairo_atomic_ptr_cmpxchg (slot, *slot, NULL);
-}
-
-static cairo_bool_t
-_atomic_store (void **slot, void *ptr)
-{
- return _cairo_atomic_ptr_cmpxchg (slot, NULL, ptr) == NULL;
-}
-
-static void *
-_freed_pool_get (freed_pool_t *pool)
-{
- void *ptr;
- int i;
-
- i = pool->top - 1;
- if (i < 0)
- i = 0;
-
- ptr = _atomic_fetch (&pool->pool[i]);
- if (ptr != NULL) {
- pool->top = i;
- return ptr;
- }
-
- /* either empty or contended */
- for (i = ARRAY_LENGTH (pool->pool); i--;) {
- ptr = _atomic_fetch (&pool->pool[i]);
- if (ptr != NULL) {
- pool->top = i;
- return ptr;
- }
- }
-
- /* empty */
- pool->top = 0;
- return NULL;
-}
-
-static void
-_freed_pool_put (freed_pool_t *pool, void *ptr)
-{
- int i = pool->top;
-
- if (_atomic_store (&pool->pool[i], ptr)) {
- pool->top = i + 1;
- return;
- }
-
- /* either full or contended */
- for (i = 0; i < ARRAY_LENGTH (pool->pool); i++) {
- if (_atomic_store (&pool->pool[i], ptr)) {
- pool->top = i + 1;
- return;
- }
- }
-
- /* full */
- pool->top = ARRAY_LENGTH (pool->pool);
- free (ptr);
-}
-
-static void
-_freed_pool_reset (freed_pool_t *pool)
-{
- int i;
-
- for (i = 0; i < ARRAY_LENGTH (pool->pool); i++) {
- free (pool->pool[i]);
- pool->pool[i] = NULL;
- }
-}
+#endif
static cairo_clip_path_t *
_cairo_clip_path_create (cairo_clip_t *clip)