diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-04-12 14:10:22 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-04-12 14:10:22 +0000 |
commit | 027b1334162c3cbaf6167038026b6d7354256093 (patch) | |
tree | dc3c8f428762ceb113ce2e87edcbd9f2ca271b1d /sys | |
parent | 845099509bda04edae00d2ea742e42df4242e874 (diff) |
Switch part of the magic hashtable over to using a TAILQ instead
of a hand-rolled list. Ideally this code needs more changes, but for
now that'll do.
Tested by many.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/pci/drm/drmP.h | 11 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_auth.c | 38 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_drv.c | 11 |
3 files changed, 20 insertions, 40 deletions
diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h index a90b9188d96..c9a2b235992 100644 --- a/sys/dev/pci/drm/drmP.h +++ b/sys/dev/pci/drm/drmP.h @@ -540,16 +540,13 @@ typedef struct drm_ioctl_desc { #define DRM_IOCTL_DEF(ioctl, func, flags) \ [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags} -typedef struct drm_magic_entry { +typedef TAILQ_HEAD(drm_magic_list, drm_magic_entry) drm_magic_head_t; +struct drm_magic_entry { drm_magic_t magic; struct drm_file *priv; - struct drm_magic_entry *next; -} drm_magic_entry_t; + TAILQ_ENTRY(drm_magic_entry) link; +}; -typedef struct drm_magic_head { - struct drm_magic_entry *head; - struct drm_magic_entry *tail; -} drm_magic_head_t; typedef struct drm_buf { int idx; /* Index into master buflist */ diff --git a/sys/dev/pci/drm/drm_auth.c b/sys/dev/pci/drm/drm_auth.c index 0994df60ba6..6e4cd1dddcd 100644 --- a/sys/dev/pci/drm/drm_auth.c +++ b/sys/dev/pci/drm/drm_auth.c @@ -52,20 +52,20 @@ drm_hash_magic(drm_magic_t magic) drm_file_t * drm_find_file(drm_device_t *dev, drm_magic_t magic) { - drm_magic_entry_t *pt; + struct drm_magic_entry *pt; int hash; hash = drm_hash_magic(magic); DRM_SPINLOCK_ASSERT(&dev->dev_lock); - for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { + TAILQ_FOREACH(pt, &dev->magiclist[hash], link) { if (pt->magic == magic) { - return pt->priv; + return (pt->priv); } } - return NULL; + return (NULL); } /** @@ -76,7 +76,7 @@ int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) { int hash; - drm_magic_entry_t *entry; + struct drm_magic_entry *entry; DRM_DEBUG("%d\n", magic); @@ -87,15 +87,7 @@ drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) if (!entry) return ENOMEM; entry->magic = magic; entry->priv = priv; - entry->next = NULL; - - if (dev->magiclist[hash].tail) { - dev->magiclist[hash].tail->next = entry; - dev->magiclist[hash].tail = entry; - } else { - dev->magiclist[hash].head = entry; - dev->magiclist[hash].tail = entry; - } + TAILQ_INSERT_TAIL(&dev->magiclist[hash], entry, link); return 0; } @@ -107,8 +99,8 @@ drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) { - drm_magic_entry_t *prev = NULL; - drm_magic_entry_t *pt; + struct drm_magic_entry *prev = NULL; + struct drm_magic_entry *pt; int hash; DRM_SPINLOCK_ASSERT(&dev->dev_lock); @@ -116,17 +108,11 @@ drm_remove_magic(drm_device_t *dev, drm_magic_t magic) DRM_DEBUG("%d\n", magic); hash = drm_hash_magic(magic); - for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) { + for (pt = TAILQ_FIRST(&dev->magiclist[hash]); + pt != TAILQ_END(&dev->magiclist[hash]); + prev = pt, pt = TAILQ_NEXT(pt, link)) { if (pt->magic == magic) { - if (dev->magiclist[hash].head == pt) { - dev->magiclist[hash].head = pt->next; - } - if (dev->magiclist[hash].tail == pt) { - dev->magiclist[hash].tail = prev; - } - if (prev) { - prev->next = pt->next; - } + TAILQ_REMOVE(&dev->magiclist[hash], pt, link); return 0; } } diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c index fd8111f06f8..a36ac17f9fb 100644 --- a/sys/dev/pci/drm/drm_drv.c +++ b/sys/dev/pci/drm/drm_drv.c @@ -381,8 +381,7 @@ drm_firstopen(drm_device_t *dev) atomic_set( &dev->counts[i], 0 ); for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) { - dev->magiclist[i].head = NULL; - dev->magiclist[i].tail = NULL; + TAILQ_INIT(&dev->magiclist[i]); } dev->lock.lock_queue = 0; @@ -405,7 +404,7 @@ drm_firstopen(drm_device_t *dev) int drm_lastclose(drm_device_t *dev) { - drm_magic_entry_t *pt, *next; + struct drm_magic_entry *pt; drm_local_map_t *map; #ifdef __FreeBSD__ drm_local_map_t *mapsave; @@ -429,11 +428,9 @@ drm_lastclose(drm_device_t *dev) } /* Clear pid list */ for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) { - for ( pt = dev->magiclist[i].head ; pt ; pt = next ) { - next = pt->next; - free(pt, M_DRM); + while ((pt = TAILQ_FIRST(&dev->magiclist[i])) != NULL) { + TAILQ_REMOVE(&dev->magiclist[i], pt, link); } - dev->magiclist[i].head = dev->magiclist[i].tail = NULL; } /* Clear AGP information */ |