From cfa778af9c70faea8c13e5cb7f80029eee0d074e Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 21 Feb 2003 23:23:09 +0000 Subject: Merge from bsd-4-0-0-branch. --- bsd-core/drm_auth.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'bsd-core/drm_auth.c') diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c index 0b411d14..a03cc918 100644 --- a/bsd-core/drm_auth.c +++ b/bsd-core/drm_auth.c @@ -116,25 +116,20 @@ int DRM(getmagic)(DRM_IOCTL_ARGS) { static drm_magic_t sequence = 0; drm_auth_t auth; - static DRM_SPINTYPE lock; - static int first = 1; DRM_DEVICE; DRM_PRIV; - if (first) { - DRM_SPININIT(lock, "drm getmagic"); - first = 0; - } - /* Find unique magic */ if (priv->magic) { auth.magic = priv->magic; } else { do { - DRM_SPINLOCK(&lock); - if (!sequence) ++sequence; /* reserve 0 */ - auth.magic = sequence++; - DRM_SPINUNLOCK(&lock); + int old = sequence; + + auth.magic = old+1; + + if (!atomic_cmpset_int(&sequence, old, auth.magic)) + continue; } while (DRM(find_file)(dev, auth.magic)); priv->magic = auth.magic; DRM(add_magic)(dev, priv, auth.magic); -- cgit v1.2.3