aboutsummaryrefslogtreecommitdiff
path: root/libdrm
diff options
context:
space:
mode:
authorAdam Jackson <ajax@nwnk.net>2006-02-20 23:09:00 +0000
committerAdam Jackson <ajax@nwnk.net>2006-02-20 23:09:00 +0000
commit22e41ef08338ae6dd59acbe6d4d8e50d83672816 (patch)
tree29bc22ae9a7be2d54b974500e92366122e1c60a3 /libdrm
parent0a211db23c0d7e22946aa25f22e9aeab6783b617 (diff)
Formatting cleanup, dead code removal. Remove N() namespacing macro,
useless. Remove SIGIO handling functions as they're server-only and properly belong in libdri.
Diffstat (limited to 'libdrm')
-rw-r--r--libdrm/ChangeLog15
-rw-r--r--libdrm/Makefile.am2
-rw-r--r--libdrm/TODO3
-rw-r--r--libdrm/xf86drm.c177
-rw-r--r--libdrm/xf86drm.h5
-rw-r--r--libdrm/xf86drmHash.c60
-rw-r--r--libdrm/xf86drmRandom.c34
-rw-r--r--libdrm/xf86drmSL.c70
8 files changed, 138 insertions, 228 deletions
diff --git a/libdrm/ChangeLog b/libdrm/ChangeLog
new file mode 100644
index 00000000..b1faa5ef
--- /dev/null
+++ b/libdrm/ChangeLog
@@ -0,0 +1,15 @@
+2006-02-20 Adam Jackson <ajax@freedesktop.org>
+
+ * ChangeLog:
+ * Makefile.am:
+ Created.
+
+ * TODO:
+ * xf86drm.c:
+ * xf86drm.h:
+ * xf86drmHash.c:
+ * xf86drmRandom.c:
+ * xf86drmSL.c:
+ Formatting cleanup, dead code removal. Remove N() namespacing macro,
+ useless. Remove SIGIO handling functions as they're server-only and
+ properly belong in libdri.
diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am
index e3d2b447..b12e87fa 100644
--- a/libdrm/Makefile.am
+++ b/libdrm/Makefile.am
@@ -27,3 +27,5 @@ libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c
libdrmincludedir = ${includedir}
libdrminclude_HEADERS = xf86drm.h
+
+EXTRA_DIST = ChangeLog TODO
diff --git a/libdrm/TODO b/libdrm/TODO
index d8cff336..b6316a29 100644
--- a/libdrm/TODO
+++ b/libdrm/TODO
@@ -7,5 +7,4 @@
- drmMsg, xf86DrvMsgVerb versus vfprintf
- drmOpenDevice tries chmod/chown if in server
- drmOpen{,ByName} tries to load kernel module if in server
- - drm*SIGIOHandler only exists in server
- All but the last three should probably be factored out into libdri.
+ All but the last two should probably be factored out into libdri.
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index 9258ed00..c9f1b2db 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -31,8 +31,6 @@
* DEALINGS IN THE SOFTWARE.
*/
-/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c,v 1.36 2003/08/24 17:35:35 tsi Exp $ */
-
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
@@ -68,13 +66,6 @@
# include "drm.h"
#endif
-/* No longer needed with CVS kernel modules on alpha
-#if defined(__alpha__) && defined(__linux__)
-extern unsigned long _bus_base(void);
-#define BUS_BASE _bus_base()
-#endif
-*/
-
/* Not all systems have MAP_FAILED defined */
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
@@ -102,11 +93,11 @@ extern unsigned long _bus_base(void);
#define DRM_MAX_MINOR 16
#endif
+/*
+ * This definition needs to be changed on some systems if dev_t is a structure.
+ * If there is a header file we can get it from, there would be best.
+ */
#ifndef makedev
- /* This definition needs to be changed on
- some systems if dev_t is a structure.
- If there is a header file we can get it
- from, there would be best. */
#define makedev(x,y) ((dev_t)(((x) << 8) | (y)))
#endif
@@ -379,7 +370,7 @@ int drmAvailable(void)
if ((fd = drmOpenMinor(0, 1)) < 0) {
#ifdef __linux__
- /* Try proc for backward Linux compatibility */
+ /* Try proc for backward Linux compatibility */
if (!access("/proc/dri/0", R_OK)) return 1;
#endif
return 0;
@@ -485,9 +476,8 @@ static int drmOpenByName(const char *name)
id = drmGetBusid(fd);
drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL");
if (!id || !*id) {
- if (id) {
+ if (id)
drmFreeBusid(id);
- }
return fd;
} else {
drmFreeBusid(id);
@@ -501,7 +491,7 @@ static int drmOpenByName(const char *name)
}
#ifdef __linux__
- /* Backward-compatibility /proc support */
+ /* Backward-compatibility /proc support */
for (i = 0; i < 8; i++) {
char proc_name[64], buf[512];
char *driver, *pt, *devstring;
@@ -515,14 +505,14 @@ static int drmOpenByName(const char *name)
buf[retcode-1] = '\0';
for (driver = pt = buf; *pt && *pt != ' '; ++pt)
;
- if (*pt) { /* Device is next */
+ if (*pt) { /* Device is next */
*pt = '\0';
if (!strcmp(driver, name)) { /* Match */
for (devstring = ++pt; *pt && *pt != ' '; ++pt)
;
if (*pt) { /* Found busid */
return drmOpenByBusid(++pt);
- } else { /* No busid */
+ } else { /* No busid */
return drmOpenDevice(strtol(devstring, NULL, 0),i);
}
}
@@ -571,8 +561,10 @@ int drmOpen(const char *name, const char *busid)
if (fd >= 0)
return fd;
}
+
if (name)
return drmOpenByName(name);
+
return -1;
}
@@ -659,7 +651,6 @@ drmVersionPtr drmGetVersion(int fd)
drmVersionPtr retval;
drm_version_t *version = drmMalloc(sizeof(*version));
- /* First, get the lengths */
version->name_len = 0;
version->name = NULL;
version->date_len = 0;
@@ -672,7 +663,6 @@ drmVersionPtr drmGetVersion(int fd)
return NULL;
}
- /* Now, allocate space and get the data */
if (version->name_len)
version->name = drmMalloc(version->name_len + 1);
if (version->date_len)
@@ -686,15 +676,11 @@ drmVersionPtr drmGetVersion(int fd)
return NULL;
}
- /* The results might not be null-terminated
- strings, so terminate them. */
-
+ /* The results might not be null-terminated strings, so terminate them. */
if (version->name_len) version->name[version->name_len] = '\0';
if (version->date_len) version->date[version->date_len] = '\0';
if (version->desc_len) version->desc[version->desc_len] = '\0';
- /* Now, copy it all back into the
- client-visible data structure... */
retval = drmMalloc(sizeof(*retval));
drmCopyVersion(retval, version);
drmFreeKernelVersion(version);
@@ -871,22 +857,12 @@ int drmAuthMagic(int fd, drm_magic_t magic)
* This function is a wrapper around the DRM_IOCTL_ADD_MAP ioctl, passing
* the arguments in a drm_map structure.
*/
-int drmAddMap(int fd,
- drm_handle_t offset,
- drmSize size,
- drmMapType type,
- drmMapFlags flags,
- drm_handle_t * handle)
+int drmAddMap(int fd, drm_handle_t offset, drmSize size, drmMapType type,
+ drmMapFlags flags, drm_handle_t *handle)
{
drm_map_t map;
map.offset = offset;
-/* No longer needed with CVS kernel modules on alpha
-#ifdef __alpha__
- if (type != DRM_SHM)
- map.offset += BUS_BASE;
-#endif
-*/
map.size = size;
map.handle = 0;
map.type = type;
@@ -1038,10 +1014,7 @@ int drmClose(int fd)
* \internal
* This function is a wrapper for mmap().
*/
-int drmMap(int fd,
- drm_handle_t handle,
- drmSize size,
- drmAddressPtr address)
+int drmMap(int fd, drm_handle_t handle, drmSize size, drmAddressPtr address)
{
static unsigned long pagesize_mask = 0;
@@ -1067,7 +1040,7 @@ int drmMap(int fd,
* \return zero on success, or a negative value on failure.
*
* \internal
- * This function is a wrapper for unmap().
+ * This function is a wrapper for munmap().
*/
int drmUnmap(drmAddress address, drmSize size)
{
@@ -1093,8 +1066,7 @@ drmBufInfoPtr drmGetBufInfo(int fd)
drmFree(info.list);
return NULL;
}
- /* Now, copy it all back into the
- client-visible data structure... */
+
retval = drmMalloc(sizeof(*retval));
retval->count = info.count;
retval->list = drmMalloc(info.count * sizeof(*retval->list));
@@ -1145,8 +1117,7 @@ drmBufMapPtr drmMapBufs(int fd)
drmFree(bufs.list);
return NULL;
}
- /* Now, copy it all back into the
- client-visible data structure... */
+
retval = drmMalloc(sizeof(*retval));
retval->count = bufs.count;
retval->list = drmMalloc(bufs.count * sizeof(*retval->list));
@@ -1206,7 +1177,6 @@ int drmDMA(int fd, drmDMAReqPtr request)
drm_dma_t dma;
int ret, i = 0;
- /* Copy to hidden structure */
dma.context = request->context;
dma.send_count = request->send_count;
dma.send_indices = request->send_list;
@@ -1284,7 +1254,7 @@ int drmUnlock(int fd, drm_context_t context)
return ioctl(fd, DRM_IOCTL_UNLOCK, &lock);
}
-drm_context_t * drmGetReservedContextList(int fd, int *count)
+drm_context_t *drmGetReservedContextList(int fd, int *count)
{
drm_ctx_res_t res;
drm_ctx_t *list;
@@ -1313,7 +1283,7 @@ drm_context_t * drmGetReservedContextList(int fd, int *count)
return retval;
}
-void drmFreeReservedContextList(drm_context_t * pt)
+void drmFreeReservedContextList(drm_context_t *pt)
{
drmFree(pt);
}
@@ -1336,7 +1306,7 @@ void drmFreeReservedContextList(drm_context_t * pt)
* This function is a wrapper around the DRM_IOCTL_ADD_CTX ioctl, passing the
* argument in a drm_ctx structure.
*/
-int drmCreateContext(int fd, drm_context_t * handle)
+int drmCreateContext(int fd, drm_context_t *handle)
{
drm_ctx_t ctx;
@@ -1359,14 +1329,12 @@ int drmSetContextFlags(int fd, drm_context_t context, drm_context_tFlags flags)
{
drm_ctx_t ctx;
- /* Context preserving means that no context
- switched are done between DMA buffers
- from one context and the next. This is
- suitable for use in the X server (which
- promises to maintain hardware context,
- or in the client-side library when
- buffers are swapped on behalf of two
- threads. */
+ /*
+ * Context preserving means that no context switches are done between DMA
+ * buffers from one context and the next. This is suitable for use in the
+ * X server (which promises to maintain hardware context), or in the
+ * client-side library when buffers are swapped on behalf of two threads.
+ */
ctx.handle = context;
ctx.flags = 0;
if (flags & DRM_CONTEXT_PRESERVED) ctx.flags |= _DRM_CONTEXT_PRESERVED;
@@ -1375,7 +1343,8 @@ int drmSetContextFlags(int fd, drm_context_t context, drm_context_tFlags flags)
return 0;
}
-int drmGetContextFlags(int fd, drm_context_t context, drm_context_tFlagsPtr flags)
+int drmGetContextFlags(int fd, drm_context_t context,
+ drm_context_tFlagsPtr flags)
{
drm_ctx_t ctx;
@@ -1412,7 +1381,7 @@ int drmDestroyContext(int fd, drm_context_t handle)
return 0;
}
-int drmCreateDrawable(int fd, drm_drawable_t * handle)
+int drmCreateDrawable(int fd, drm_drawable_t *handle)
{
drm_draw_t draw;
if (ioctl(fd, DRM_IOCTL_ADD_DRAW, &draw)) return -errno;
@@ -1941,7 +1910,8 @@ void *drmGetContextTag(int fd, drm_context_t context)
return value;
}
-int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id, drm_handle_t handle)
+int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
+ drm_handle_t handle)
{
drm_ctx_priv_map_t map;
@@ -1952,7 +1922,8 @@ int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id, drm_handle_t handl
return 0;
}
-int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id, drm_handle_t * handle)
+int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id,
+ drm_handle_t *handle)
{
drm_ctx_priv_map_t map;
@@ -2132,7 +2103,7 @@ int drmGetStats(int fd, drmStatsT *stats)
* It issues a read-write ioctl given by
* \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
*/
-int drmSetInterfaceVersion(int fd, drmSetVersion *version )
+int drmSetInterfaceVersion(int fd, drmSetVersion *version)
{
int retcode = 0;
drm_set_version_t sv;
@@ -2194,8 +2165,8 @@ int drmCommandNone(int fd, unsigned long drmCommandIndex)
* It issues a read ioctl given by
* \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
*/
-int drmCommandRead(int fd, unsigned long drmCommandIndex,
- void *data, unsigned long size )
+int drmCommandRead(int fd, unsigned long drmCommandIndex, void *data,
+ unsigned long size)
{
unsigned long request;
@@ -2223,8 +2194,8 @@ int drmCommandRead(int fd, unsigned long drmCommandIndex,
* It issues a write ioctl given by
* \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
*/
-int drmCommandWrite(int fd, unsigned long drmCommandIndex,
- void *data, unsigned long size )
+int drmCommandWrite(int fd, unsigned long drmCommandIndex, void *data,
+ unsigned long size)
{
unsigned long request;
@@ -2252,8 +2223,8 @@ int drmCommandWrite(int fd, unsigned long drmCommandIndex,
* It issues a read-write ioctl given by
* \code DRM_COMMAND_BASE + drmCommandIndex \endcode.
*/
-int drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
- void *data, unsigned long size )
+int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data,
+ unsigned long size)
{
unsigned long request;
@@ -2265,69 +2236,3 @@ int drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
}
return 0;
}
-
-#if defined(XFree86Server)
-static void drmSIGIOHandler(int interrupt, void *closure)
-{
- unsigned long key;
- void *value;
- ssize_t count;
- drm_ctx_t ctx;
- typedef void (*_drmCallback)(int, void *, void *);
- char buf[256];
- drm_context_t old;
- drm_context_t new;
- void *oldctx;
- void *newctx;
- char *pt;
- drmHashEntry *entry;
-
- if (!drmHashTable) return;
- if (drmHashFirst(drmHashTable, &key, &value)) {
- entry = value;
- do {
-#if 0
- fprintf(stderr, "Trying %d\n", entry->fd);
-#endif
- if ((count = read(entry->fd, buf, sizeof(buf))) > 0) {
- buf[count] = '\0';
-#if 0
- fprintf(stderr, "Got %s\n", buf);
-#endif
-
- for (pt = buf; *pt != ' '; ++pt); /* Find first space */
- ++pt;
- old = strtol(pt, &pt, 0);
- new = strtol(pt, NULL, 0);
- oldctx = drmGetContextTag(entry->fd, old);
- newctx = drmGetContextTag(entry->fd, new);
-#if 0
- fprintf(stderr, "%d %d %p %p\n", old, new, oldctx, newctx);
-#endif
- ((_drmCallback)entry->f)(entry->fd, oldctx, newctx);
- ctx.handle = new;
- ioctl(entry->fd, DRM_IOCTL_NEW_CTX, &ctx);
- }
- } while (drmHashNext(drmHashTable, &key, &value));
- }
-}
-
-int drmInstallSIGIOHandler(int fd, void (*f)(int, void *, void *))
-{
- drmHashEntry *entry;
-
- entry = drmGetEntry(fd);
- entry->f = f;
-
- return xf86InstallSIGIOHandler(fd, drmSIGIOHandler, 0);
-}
-
-int drmRemoveSIGIOHandler(int fd)
-{
- drmHashEntry *entry = drmGetEntry(fd);
-
- entry->f = NULL;
-
- return xf86RemoveSIGIOHandler(fd);
-}
-#endif
diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h
index 4be417a6..48a18f29 100644
--- a/libdrm/xf86drm.h
+++ b/libdrm/xf86drm.h
@@ -546,11 +546,6 @@ extern int drmCreateDrawable(int fd, drm_drawable_t * handle);
extern int drmDestroyDrawable(int fd, drm_drawable_t handle);
extern int drmCtlInstHandler(int fd, int irq);
extern int drmCtlUninstHandler(int fd);
-extern int drmInstallSIGIOHandler(int fd,
- void (*f)(int fd,
- void *oldctx,
- void *newctx));
-extern int drmRemoveSIGIOHandler(int fd);
/* General user-level programmer's API: authenticated client and/or X */
extern int drmMap(int fd,
diff --git a/libdrm/xf86drmHash.c b/libdrm/xf86drmHash.c
index c3e7f0d7..71d3d895 100644
--- a/libdrm/xf86drmHash.c
+++ b/libdrm/xf86drmHash.c
@@ -91,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 */
@@ -135,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)
@@ -170,7 +168,7 @@ static unsigned long HashHash(unsigned long key)
return hash;
}
-void *N(HashCreate)(void)
+void *drmHashCreate(void)
{
HashTablePtr table;
int i;
@@ -187,7 +185,7 @@ void *N(HashCreate)(void)
return table;
}
-int N(HashDestroy)(void *t)
+int drmHashDestroy(void *t)
{
HashTablePtr table = (HashTablePtr)t;
HashBucketPtr bucket;
@@ -238,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;
@@ -251,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;
@@ -273,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;
@@ -290,7 +288,7 @@ 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;
@@ -306,7 +304,7 @@ int N(HashNext)(void *t, unsigned long *key, void **value)
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;
@@ -314,7 +312,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
@@ -363,7 +361,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:
@@ -393,50 +391,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;
}
diff --git a/libdrm/xf86drmRandom.c b/libdrm/xf86drmRandom.c
index 301aaf4c..3f5bf611 100644
--- a/libdrm/xf86drmRandom.c
+++ b/libdrm/xf86drmRandom.c
@@ -94,8 +94,6 @@
# endif
#endif
-#define N(x) drm##x
-
#define RANDOM_MAGIC 0xfeedbeef
#define RANDOM_DEBUG 0
@@ -118,13 +116,13 @@ typedef struct RandomState {
} RandomState;
#if RANDOM_MAIN
-extern void *N(RandomCreate)(unsigned long seed);
-extern int N(RandomDestroy)(void *state);
-extern unsigned long N(Random)(void *state);
-extern double N(RandomDouble)(void *state);
+extern void *drmRandomCreate(unsigned long seed);
+extern int drmRandomDestroy(void *state);
+extern unsigned long drmRandom(void *state);
+extern double drmRandomDouble(void *state);
#endif
-void *N(RandomCreate)(unsigned long seed)
+void *drmRandomCreate(unsigned long seed)
{
RandomState *state;
@@ -154,13 +152,13 @@ void *N(RandomCreate)(unsigned long seed)
return state;
}
-int N(RandomDestroy)(void *state)
+int drmRandomDestroy(void *state)
{
RANDOM_FREE(state);
return 0;
}
-unsigned long N(Random)(void *state)
+unsigned long drmRandom(void *state)
{
RandomState *s = (RandomState *)state;
long hi;
@@ -174,11 +172,11 @@ unsigned long N(Random)(void *state)
return s->seed;
}
-double N(RandomDouble)(void *state)
+double drmRandomDouble(void *state)
{
RandomState *s = (RandomState *)state;
- return (double)N(Random)(state)/(double)s->m;
+ return (double)drmRandom(state)/(double)s->m;
}
#if RANDOM_MAIN
@@ -188,15 +186,15 @@ static void check_period(long seed)
unsigned long initial;
void *state;
- state = N(RandomCreate)(seed);
- initial = N(Random)(state);
+ state = drmRandomCreate(seed);
+ initial = drmRandom(state);
++count;
- while (initial != N(Random)(state)) {
+ while (initial != drmRandom(state)) {
if (!++count) break;
}
printf("With seed of %10ld, period = %10lu (0x%08lx)\n",
seed, count, count);
- N(RandomDestroy)(state);
+ drmRandomDestroy(state);
}
int main(void)
@@ -205,14 +203,14 @@ int main(void)
int i;
unsigned long rand;
- state = N(RandomCreate)(1);
+ state = drmRandomCreate(1);
for (i = 0; i < 10000; i++) {
- rand = N(Random)(state);
+ rand = drmRandom(state);
}
printf("After 10000 iterations: %lu (%lu expected): %s\n",
rand, state->check,
rand - state->check ? "*INCORRECT*" : "CORRECT");
- N(RandomDestroy)(state);
+ drmRandomDestroy(state);
printf("Checking periods...\n");
check_period(1);
diff --git a/libdrm/xf86drmSL.c b/libdrm/xf86drmSL.c
index 5f3c88d2..ab2cc098 100644
--- a/libdrm/xf86drmSL.c
+++ b/libdrm/xf86drmSL.c
@@ -62,8 +62,6 @@
# endif
#endif
-#define N(x) drm##x
-
#define SL_LIST_MAGIC 0xfacade00LU
#define SL_ENTRY_MAGIC 0x00fab1edLU
#define SL_FREED_MAGIC 0xdecea5edLU
@@ -103,15 +101,15 @@ typedef struct SkipList {
} SkipList, *SkipListPtr;
#if SL_MAIN
-extern void *N(SLCreate)(void);
-extern int N(SLDestroy)(void *l);
-extern int N(SLLookup)(void *l, unsigned long key, void **value);
-extern int N(SLInsert)(void *l, unsigned long key, void *value);
-extern int N(SLDelete)(void *l, unsigned long key);
-extern int N(SLNext)(void *l, unsigned long *key, void **value);
-extern int N(SLFirst)(void *l, unsigned long *key, void **value);
-extern void N(SLDump)(void *l);
-extern int N(SLLookupNeighbors)(void *l, unsigned long key,
+extern void *drmSLCreate(void);
+extern int drmSLDestroy(void *l);
+extern int drmSLLookup(void *l, unsigned long key, void **value);
+extern int drmSLInsert(void *l, unsigned long key, void *value);
+extern int drmSLDelete(void *l, unsigned long key);
+extern int drmSLNext(void *l, unsigned long *key, void **value);
+extern int drmSLFirst(void *l, unsigned long *key, void **value);
+extern void drmSLDump(void *l);
+extern int drmSLLookupNeighbors(void *l, unsigned long key,
unsigned long *prev_key, void **prev_value,
unsigned long *next_key, void **next_value);
#endif
@@ -144,7 +142,7 @@ static int SLRandomLevel(void)
return level;
}
-void *N(SLCreate)(void)
+void *drmSLCreate(void)
{
SkipListPtr list;
int i;
@@ -161,7 +159,7 @@ void *N(SLCreate)(void)
return list;
}
-int N(SLDestroy)(void *l)
+int drmSLDestroy(void *l)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
@@ -198,7 +196,7 @@ static SLEntryPtr SLLocate(void *l, unsigned long key, SLEntryPtr *update)
return entry->forward[0];
}
-int N(SLInsert)(void *l, unsigned long key, void *value)
+int drmSLInsert(void *l, unsigned long key, void *value)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
@@ -231,7 +229,7 @@ int N(SLInsert)(void *l, unsigned long key, void *value)
return 0; /* Added to table */
}
-int N(SLDelete)(void *l, unsigned long key)
+int drmSLDelete(void *l, unsigned long key)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr update[SL_MAX_LEVEL + 1];
@@ -258,7 +256,7 @@ int N(SLDelete)(void *l, unsigned long key)
return 0;
}
-int N(SLLookup)(void *l, unsigned long key, void **value)
+int drmSLLookup(void *l, unsigned long key, void **value)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr update[SL_MAX_LEVEL + 1];
@@ -274,7 +272,7 @@ int N(SLLookup)(void *l, unsigned long key, void **value)
return -1;
}
-int N(SLLookupNeighbors)(void *l, unsigned long key,
+int drmSLLookupNeighbors(void *l, unsigned long key,
unsigned long *prev_key, void **prev_value,
unsigned long *next_key, void **next_value)
{
@@ -301,7 +299,7 @@ int N(SLLookupNeighbors)(void *l, unsigned long key,
return retcode;
}
-int N(SLNext)(void *l, unsigned long *key, void **value)
+int drmSLNext(void *l, unsigned long *key, void **value)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
@@ -320,18 +318,18 @@ int N(SLNext)(void *l, unsigned long *key, void **value)
return 0;
}
-int N(SLFirst)(void *l, unsigned long *key, void **value)
+int drmSLFirst(void *l, unsigned long *key, void **value)
{
SkipListPtr list = (SkipListPtr)l;
if (list->magic != SL_LIST_MAGIC) return -1; /* Bad magic */
list->p0 = list->head->forward[0];
- return N(SLNext)(list, key, value);
+ return drmSLNext(list, key, value);
}
/* Dump internal data structures for debugging. */
-void N(SLDump)(void *l)
+void drmSLDump(void *l)
{
SkipListPtr list = (SkipListPtr)l;
SLEntryPtr entry;
@@ -371,10 +369,10 @@ static void print(SkipListPtr list)
unsigned long key;
void *value;
- if (N(SLFirst)(list, &key, &value)) {
+ if (drmSLFirst(list, &key, &value)) {
do {
printf("key = %5lu, value = %p\n", key, value);
- } while (N(SLNext)(list, &key, &value));
+ } while (drmSLNext(list, &key, &value));
}
}
@@ -392,27 +390,27 @@ static double do_time(int size, int iter)
SL_RANDOM_INIT(12345);
- list = N(SLCreate)();
+ list = drmSLCreate();
for (i = 0; i < size; i++) {
keys[i] = SL_RANDOM;
- N(SLInsert)(list, keys[i], NULL);
+ drmSLInsert(list, keys[i], NULL);
}
previous = 0;
- if (N(SLFirst)(list, &key, &value)) {
+ if (drmSLFirst(list, &key, &value)) {
do {
if (key <= previous) {
printf( "%lu !< %lu\n", previous, key);
}
previous = key;
- } while (N(SLNext)(list, &key, &value));
+ } while (drmSLNext(list, &key, &value));
}
gettimeofday(&start, NULL);
for (j = 0; j < iter; j++) {
for (i = 0; i < size; i++) {
- if (N(SLLookup)(list, keys[i], &value))
+ if (drmSLLookup(list, keys[i], &value))
printf("Error %lu %d\n", keys[i], i);
}
}
@@ -423,7 +421,7 @@ static double do_time(int size, int iter)
printf("%0.2f microseconds for list length %d\n", usec, size);
- N(SLDestroy)(list);
+ drmSLDestroy(list);
return usec;
}
@@ -448,15 +446,15 @@ int main(void)
SkipListPtr list;
double usec, usec2, usec3, usec4;
- list = N(SLCreate)();
+ list = drmSLCreate();
printf( "list at %p\n", list);
print(list);
printf("\n==============================\n\n");
- N(SLInsert)(list, 123, NULL);
- N(SLInsert)(list, 213, NULL);
- N(SLInsert)(list, 50, NULL);
+ drmSLInsert(list, 123, NULL);
+ drmSLInsert(list, 213, NULL);
+ drmSLInsert(list, 50, NULL);
print(list);
printf("\n==============================\n\n");
@@ -469,12 +467,12 @@ int main(void)
print_neighbors(list, 256);
printf("\n==============================\n\n");
- N(SLDelete)(list, 50);
+ drmSLDelete(list, 50);
print(list);
printf("\n==============================\n\n");
- N(SLDump)(list);
- N(SLDestroy)(list);
+ drmSLDump(list);
+ drmSLDestroy(list);
printf("\n==============================\n\n");
usec = do_time(100, 10000);