[cairo-commit] src/cairo-mempool.c src/cairo-xcb-shm.c

Chris Wilson ickle at kemper.freedesktop.org
Sat Dec 1 01:25:31 PST 2012


 src/cairo-mempool.c |    9 +++++++++
 src/cairo-xcb-shm.c |   14 +++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

New commits:
commit a0fb1391315033de54368715a8855aedea258e67
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat Dec 1 09:21:15 2012 +0000

    mempool: Reduce the assertion into an alignment adjustment for the base
    
    Instead of asserting that the caller passed in a chunk-aligned base
    pointer, just perform the fixup whilst initialising the mempool. This
    means that the caller (xcb!) cannot assume that the mempool->base is
    then the same base pointer as passed in and so needs to store it
    separately for use in computing SHM offsets.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-mempool.c b/src/cairo-mempool.c
index 296b739..96e4a62 100644
--- a/src/cairo-mempool.c
+++ b/src/cairo-mempool.c
@@ -283,9 +283,18 @@ _cairo_mempool_init (cairo_mempool_t *pool,
 		      void *base, size_t bytes,
 		      int min_bits, int num_sizes)
 {
+    unsigned long tmp;
     int num_blocks;
     int i;
 
+    /* Align the start to an integral chunk */
+    tmp = ((unsigned long) base) & ((1 << min_bits) - 1);
+    if (tmp) {
+	tmp = (1 << min_bits) - tmp;
+	base = (char *)base + tmp;
+	bytes -= tmp;
+    }
+
     assert ((((unsigned long) base) & ((1 << min_bits) - 1)) == 0);
     assert (num_sizes < ARRAY_LENGTH (pool->free));
 
diff --git a/src/cairo-xcb-shm.c b/src/cairo-xcb-shm.c
index 7c2a675..2be2dac 100644
--- a/src/cairo-xcb-shm.c
+++ b/src/cairo-xcb-shm.c
@@ -63,6 +63,7 @@ typedef enum {
 struct _cairo_xcb_shm_mem_pool {
     int shmid;
     uint32_t shmseg;
+    void *shm;
 
     cairo_mempool_t mem;
 
@@ -74,7 +75,7 @@ _cairo_xcb_shm_mem_pool_destroy (cairo_xcb_shm_mem_pool_t *pool)
 {
     cairo_list_del (&pool->link);
 
-    shmdt (pool->mem.base);
+    shmdt (pool->shm);
     _cairo_mempool_fini (&pool->mem);
 
     free (pool);
@@ -160,7 +161,6 @@ _cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *connection,
     size_t shm_allocated = 0;
     void *mem = NULL;
     cairo_status_t status;
-    void *base;
 
     assert (connection->flags & CAIRO_XCB_HAS_SHM);
 
@@ -240,18 +240,18 @@ _cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *connection,
 	return CAIRO_INT_STATUS_UNSUPPORTED;
     }
 
-    base = shmat (pool->shmid, NULL, 0);
-    if (unlikely (base == (char *) -1)) {
+    pool->shm = shmat (pool->shmid, NULL, 0);
+    if (unlikely (pool->shm == (char *) -1)) {
 	shmctl (pool->shmid, IPC_RMID, NULL);
 	free (pool);
 	CAIRO_MUTEX_UNLOCK (connection->shm_mutex);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
-    status = _cairo_mempool_init (&pool->mem, base, bytes,
+    status = _cairo_mempool_init (&pool->mem, pool->shm, bytes,
 				  minbits, maxbits - minbits + 1);
     if (unlikely (status)) {
-	shmdt (base);
+	shmdt (pool->shm);
 	free (pool);
 	CAIRO_MUTEX_UNLOCK (connection->shm_mutex);
 	return status;
@@ -275,7 +275,7 @@ _cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *connection,
     shm_info->pool = pool;
     shm_info->shm = pool->shmseg;
     shm_info->size = size;
-    shm_info->offset = (char *) mem - (char *) pool->mem.base;
+    shm_info->offset = (char *) mem - (char *) pool->shm;
     shm_info->mem = mem;
     shm_info->sync.sequence = XCB_NONE;
 


More information about the cairo-commit mailing list