OSDN Git Service

i915: Do not wait for pending flips on both pipes at the same time.
[android-x86/external-libdrm.git] / libdrm / xf86drmHash.c
index 3ee9c02..a1908d0 100644 (file)
  *
  */
 
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
 #define HASH_MAIN 0
 
 #if HASH_MAIN
@@ -87,8 +91,6 @@
 # endif
 #endif
 
-#define N(x)  drm##x
-
 #define HASH_MAGIC 0xdeadbeef
 #define HASH_DEBUG 0
 #define HASH_SIZE  512         /* Good for about 100 entries */
@@ -131,11 +133,11 @@ typedef struct HashTable {
 } HashTable, *HashTablePtr;
 
 #if HASH_MAIN
-extern void *N(HashCreate)(void);
-extern int  N(HashDestroy)(void *t);
-extern int  N(HashLookup)(void *t, unsigned long key, unsigned long *value);
-extern int  N(HashInsert)(void *t, unsigned long key, unsigned long value);
-extern int  N(HashDelete)(void *t, unsigned long key);
+extern void *drmHashCreate(void);
+extern int  drmHashDestroy(void *t);
+extern int  drmHashLookup(void *t, unsigned long key, unsigned long *value);
+extern int  drmHashInsert(void *t, unsigned long key, unsigned long value);
+extern int  drmHashDelete(void *t, unsigned long key);
 #endif
 
 static unsigned long HashHash(unsigned long key)
@@ -166,7 +168,7 @@ static unsigned long HashHash(unsigned long key)
     return hash;
 }
 
-void *N(HashCreate)(void)
+void *drmHashCreate(void)
 {
     HashTablePtr table;
     int          i;
@@ -183,7 +185,7 @@ void *N(HashCreate)(void)
     return table;
 }
 
-int N(HashDestroy)(void *t)
+int drmHashDestroy(void *t)
 {
     HashTablePtr  table = (HashTablePtr)t;
     HashBucketPtr bucket;
@@ -234,7 +236,7 @@ static HashBucketPtr HashFind(HashTablePtr table,
     return NULL;
 }
 
-int N(HashLookup)(void *t, unsigned long key, void **value)
+int drmHashLookup(void *t, unsigned long key, void **value)
 {
     HashTablePtr  table = (HashTablePtr)t;
     HashBucketPtr bucket;
@@ -247,7 +249,7 @@ int N(HashLookup)(void *t, unsigned long key, void **value)
     return 0;                  /* Found */
 }
 
-int N(HashInsert)(void *t, unsigned long key, void *value)
+int drmHashInsert(void *t, unsigned long key, void *value)
 {
     HashTablePtr  table = (HashTablePtr)t;
     HashBucketPtr bucket;
@@ -269,7 +271,7 @@ int N(HashInsert)(void *t, unsigned long key, void *value)
     return 0;                  /* Added to table */
 }
 
-int N(HashDelete)(void *t, unsigned long key)
+int drmHashDelete(void *t, unsigned long key)
 {
     HashTablePtr  table = (HashTablePtr)t;
     unsigned long hash;
@@ -286,23 +288,24 @@ int N(HashDelete)(void *t, unsigned long key)
     return 0;
 }
 
-int N(HashNext)(void *t, unsigned long *key, void **value)
+int drmHashNext(void *t, unsigned long *key, void **value)
 {
     HashTablePtr  table = (HashTablePtr)t;
 
-    for (; table->p0 < HASH_SIZE;
-        ++table->p0, table->p1 = table->buckets[table->p0]) {
+    while (table->p0 < HASH_SIZE) {
        if (table->p1) {
            *key       = table->p1->key;
            *value     = table->p1->value;
            table->p1  = table->p1->next;
            return 1;
        }
+       table->p1 = table->buckets[table->p0];
+       ++table->p0;
     }
     return 0;
 }
 
-int N(HashFirst)(void *t, unsigned long *key, void **value)
+int drmHashFirst(void *t, unsigned long *key, void **value)
 {
     HashTablePtr  table = (HashTablePtr)t;
 
@@ -310,7 +313,7 @@ int N(HashFirst)(void *t, unsigned long *key, void **value)
 
     table->p0 = 0;
     table->p1 = table->buckets[0];
-    return N(HashNext)(table, key, value);
+    return drmHashNext(table, key, value);
 }
 
 #if HASH_MAIN
@@ -359,7 +362,7 @@ static void check_table(HashTablePtr table,
                        unsigned long key, unsigned long value)
 {
     unsigned long retval  = 0;
-    int           retcode = N(HashLookup)(table, key, &retval);
+    int           retcode = drmHashLookup(table, key, &retval);
 
     switch (retcode) {
     case -1:
@@ -389,50 +392,50 @@ int main(void)
     int          i;
 
     printf("\n***** 256 consecutive integers ****\n");
-    table = N(HashCreate)();
-    for (i = 0; i < 256; i++) N(HashInsert)(table, i, i);
+    table = drmHashCreate();
+    for (i = 0; i < 256; i++) drmHashInsert(table, i, i);
     for (i = 0; i < 256; i++) check_table(table, i, i);
     for (i = 256; i >= 0; i--) check_table(table, i, i);
     compute_dist(table);
-    N(HashDestroy)(table);
+    drmHashDestroy(table);
 
     printf("\n***** 1024 consecutive integers ****\n");
-    table = N(HashCreate)();
-    for (i = 0; i < 1024; i++) N(HashInsert)(table, i, i);
+    table = drmHashCreate();
+    for (i = 0; i < 1024; i++) drmHashInsert(table, i, i);
     for (i = 0; i < 1024; i++) check_table(table, i, i);
     for (i = 1024; i >= 0; i--) check_table(table, i, i);
     compute_dist(table);
-    N(HashDestroy)(table);
+    drmHashDestroy(table);
 
     printf("\n***** 1024 consecutive page addresses (4k pages) ****\n");
-    table = N(HashCreate)();
-    for (i = 0; i < 1024; i++) N(HashInsert)(table, i*4096, i);
+    table = drmHashCreate();
+    for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, i);
     for (i = 0; i < 1024; i++) check_table(table, i*4096, i);
     for (i = 1024; i >= 0; i--) check_table(table, i*4096, i);
     compute_dist(table);
-    N(HashDestroy)(table);
+    drmHashDestroy(table);
 
     printf("\n***** 1024 random integers ****\n");
-    table = N(HashCreate)();
+    table = drmHashCreate();
     srandom(0xbeefbeef);
-    for (i = 0; i < 1024; i++) N(HashInsert)(table, random(), i);
+    for (i = 0; i < 1024; i++) drmHashInsert(table, random(), i);
     srandom(0xbeefbeef);
     for (i = 0; i < 1024; i++) check_table(table, random(), i);
     srandom(0xbeefbeef);
     for (i = 0; i < 1024; i++) check_table(table, random(), i);
     compute_dist(table);
-    N(HashDestroy)(table);
+    drmHashDestroy(table);
 
     printf("\n***** 5000 random integers ****\n");
-    table = N(HashCreate)();
+    table = drmHashCreate();
     srandom(0xbeefbeef);
-    for (i = 0; i < 5000; i++) N(HashInsert)(table, random(), i);
+    for (i = 0; i < 5000; i++) drmHashInsert(table, random(), i);
     srandom(0xbeefbeef);
     for (i = 0; i < 5000; i++) check_table(table, random(), i);
     srandom(0xbeefbeef);
     for (i = 0; i < 5000; i++) check_table(table, random(), i);
     compute_dist(table);
-    N(HashDestroy)(table);
+    drmHashDestroy(table);
 
     return 0;
 }