pb_bufmgr_cache: add is_buffer_busy hook and use it instead of non-blocking map
authorMarek Olšák <maraeo@gmail.com>
Sun, 13 Feb 2011 08:26:07 +0000 (09:26 +0100)
committerMarek Olšák <maraeo@gmail.com>
Mon, 14 Feb 2011 20:51:01 +0000 (21:51 +0100)
This is cleaner and implementing the hook is optional.

src/gallium/auxiliary/pipebuffer/pb_bufmgr.h
src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c

index 2ef02160f23ef606ce9b67dc7461678fa5b4398e..960068c494db584ae2a81bf0dc01236b91bcb70a 100644 (file)
@@ -82,6 +82,10 @@ struct pb_manager
     */
    void
    (*flush)( struct pb_manager *mgr );
+
+   boolean
+   (*is_buffer_busy)( struct pb_manager *mgr,
+                      struct pb_buffer *buf );
 };
 
 
index a6eb4039621f6fbfe047f62e337b0740c949b54f..25accefa8d6412807397fd087ac897b47620874d 100644 (file)
@@ -227,8 +227,6 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,
                           pb_size size,
                           const struct pb_desc *desc)
 {
-   void *map;
-
    if(buf->base.base.size < size)
       return 0;
 
@@ -242,13 +240,18 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,
    if(!pb_check_usage(desc->usage, buf->base.base.usage))
       return 0;
 
-   map = pb_map(buf->buffer, PB_USAGE_DONTBLOCK, NULL);
-   if (!map) {
-      return -1;
+   if (buf->mgr->provider->is_buffer_busy) {
+      if (buf->mgr->provider->is_buffer_busy(buf->mgr->provider, buf->buffer))
+         return -1;
+   } else {
+      void *ptr = pb_map(buf->buffer, PB_USAGE_DONTBLOCK, NULL);
+
+      if (!ptr)
+         return -1;
+
+      pb_unmap(buf->buffer);
    }
 
-   pb_unmap(buf->buffer);
-   
    return 1;
 }