llvmpipe/images: handle undefined atomic without crashing
[mesa.git] / src / gallium / auxiliary / cso_cache / cso_hash.h
index 85f3e276c6ae37a28e458ba06f00b5a4b43058b9..d6eeb04f1ac8e3e966b8cfa80c855ed4e5733043 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * had the same key (e.g. memcmp could be used on the data to check
  * that)
  * 
- * @author Zack Rusin <zack@tungstengraphics.com>
+ * @author Zack Rusin <zackr@vmware.com>
  */
 
 #ifndef CSO_HASH_H
 #define CSO_HASH_H
 
+#include "pipe/p_compiler.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
-struct cso_hash;
-struct cso_node;
+struct cso_node {
+   struct cso_node *next;
+   unsigned key;
+   void *value;
+};
 
+struct cso_hash {
+   union {
+      struct cso_hash_data *d;
+      struct cso_node      *e;
+   } data;
+};
 
 struct cso_hash_iter {
    struct cso_hash *hash;
@@ -95,10 +105,13 @@ struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash);
  */
 struct cso_hash_iter cso_hash_find(struct cso_hash *hash, unsigned key);
 
+/**
+ * Returns true if a value with the given key exists in the hash
+ */
+boolean   cso_hash_contains(struct cso_hash *hash, unsigned key);
+
 
-int       cso_hash_iter_is_null(struct cso_hash_iter iter);
 unsigned  cso_hash_iter_key(struct cso_hash_iter iter);
-void     *cso_hash_iter_data(struct cso_hash_iter iter);
 
 
 struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter);
@@ -115,6 +128,21 @@ void *cso_hash_find_data_from_template( struct cso_hash *hash,
                                        void *templ,
                                        int size );
 
+static inline int
+cso_hash_iter_is_null(struct cso_hash_iter iter)
+{
+   if (!iter.node || iter.node == iter.hash->data.e)
+      return 1;
+   return 0;
+}
+
+static inline void *
+cso_hash_iter_data(struct cso_hash_iter iter)
+{
+   if (!iter.node || iter.hash->data.e == iter.node)
+      return 0;
+   return iter.node->value;
+}
 
 #ifdef __cplusplus
 }