pipebuffer: Verify usage flag consistency. Minor cleanups.

This commit is contained in:
José Fonseca
2008-07-02 12:22:51 +09:00
parent 66b48202c2
commit ea4ca10b1b
8 changed files with 43 additions and 17 deletions

View File

@@ -204,13 +204,24 @@ pb_reference(struct pb_buffer **dst,
/**
* Utility function to check whether a requested alignment is consistent with
* the provided alignment or not.
* Utility function to check whether the provided alignment is consistent with
* the requested or not.
*/
static INLINE int
static INLINE boolean
pb_check_alignment(size_t requested, size_t provided)
{
return requested <= provided && (provided % requested) == 0;
return requested <= provided && (provided % requested) == 0 ? TRUE : FALSE;
}
/**
* Utility function to check whether the provided alignment is consistent with
* the requested or not.
*/
static INLINE boolean
pb_check_usage(unsigned requested, unsigned provided)
{
return (requested & provided) == provided ? TRUE : FALSE;
}

View File

@@ -406,7 +406,7 @@ fenced_buffer_list_create(struct pipe_winsys *winsys)
{
struct fenced_buffer_list *fenced_list;
fenced_list = (struct fenced_buffer_list *)CALLOC(1, sizeof(*fenced_list));
fenced_list = CALLOC_STRUCT(fenced_buffer_list);
if (!fenced_list)
return NULL;

View File

@@ -88,6 +88,9 @@ pb_alt_manager_create(struct pb_manager *provider1,
{
struct pb_alt_manager *mgr;
if(!provider1 || !provider2)
return NULL;
mgr = CALLOC_STRUCT(pb_alt_manager);
if (!mgr)
return NULL;

View File

@@ -217,7 +217,8 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,
if(!pb_check_alignment(desc->alignment, buf->base.base.alignment))
return FALSE;
/* XXX: check usage too? */
if(!pb_check_usage(desc->usage, buf->base.base.usage))
return FALSE;
return TRUE;
}
@@ -282,7 +283,7 @@ pb_cache_manager_create_buffer(struct pb_manager *_mgr,
assert(buf->buffer->base.refcount >= 1);
assert(pb_check_alignment(desc->alignment, buf->buffer->base.alignment));
assert((buf->buffer->base.usage & desc->usage) == desc->usage);
assert(pb_check_usage(desc->usage, buf->buffer->base.usage));
assert(buf->buffer->base.size >= size);
buf->base.base.refcount = 1;
@@ -331,7 +332,10 @@ pb_cache_manager_create(struct pb_manager *provider,
{
struct pb_cache_manager *mgr;
mgr = (struct pb_cache_manager *)CALLOC(1, sizeof(*mgr));
if(!provider)
return NULL;
mgr = CALLOC_STRUCT(pb_cache_manager);
if (!mgr)
return NULL;

View File

@@ -117,7 +117,7 @@ fenced_bufmgr_create(struct pb_manager *provider,
if(!provider)
return NULL;
fenced_mgr = (struct fenced_pb_manager *)CALLOC(1, sizeof(*fenced_mgr));
fenced_mgr = CALLOC_STRUCT(fenced_pb_manager);
if (!fenced_mgr)
return NULL;

View File

@@ -29,7 +29,7 @@
* \file
* Buffer manager using the old texture memory manager.
*
* \author Jos<EFBFBD> Fonseca <jrfonseca@tungstengraphics.com>
* \author José Fonseca <jrfonseca@tungstengraphics.com>
*/
@@ -271,8 +271,8 @@ mm_bufmgr_create(struct pb_manager *provider,
struct pb_manager *mgr;
struct pb_desc desc;
assert(provider);
assert(provider->create_buffer);
if(!provider)
return NULL;
memset(&desc, 0, sizeof(desc));
desc.alignment = 1 << align2;

View File

@@ -30,8 +30,8 @@
* \file
* Batch buffer pool management.
*
* \author Jos<EFBFBD> Fonseca <jrfonseca-at-tungstengraphics-dot-com>
* \author Thomas Hellstr<EFBFBD>m <thomas-at-tungstengraphics-dot-com>
* \author José Fonseca <jrfonseca-at-tungstengraphics-dot-com>
* \author Thomas Hellström <thomas-at-tungstengraphics-dot-com>
*/
@@ -229,7 +229,10 @@ pool_bufmgr_create(struct pb_manager *provider,
struct pool_buffer *pool_buf;
size_t i;
pool = (struct pool_pb_manager *)CALLOC(1, sizeof(*pool));
if(!provider)
return NULL;
pool = CALLOC_STRUCT(pool_pb_manager);
if (!pool)
return NULL;

View File

@@ -324,8 +324,10 @@ pb_slab_manager_create_buffer(struct pb_manager *_mgr,
if(!pb_check_alignment(desc->alignment, mgr->bufSize))
return NULL;
/* XXX: check for compatible buffer usage too? */
assert(pb_check_usage(desc->usage, mgr->desc.usage));
if(!pb_check_usage(desc->usage, mgr->desc.usage))
return NULL;
_glthread_LOCK_MUTEX(mgr->mutex);
if (mgr->slabs.next == &mgr->slabs) {
(void) pb_slab_create(mgr);
@@ -438,6 +440,9 @@ pb_slab_range_manager_create(struct pb_manager *provider,
size_t bufSize;
unsigned i;
if(!provider)
return NULL;
mgr = CALLOC_STRUCT(pb_slab_range_manager);
if (!mgr)
goto out_err0;