summaryrefslogtreecommitdiff
path: root/bsd-core/drm_auth.c
diff options
context:
space:
mode:
authorEric Anholt <anholt@freebsd.org>2003-02-21 23:23:09 +0000
committerEric Anholt <anholt@freebsd.org>2003-02-21 23:23:09 +0000
commitcfa778af9c70faea8c13e5cb7f80029eee0d074e (patch)
tree15483e64b6c2b56d3bb0f247df9df2c2602e0404 /bsd-core/drm_auth.c
parenta64472d18493de575a7636704b45babe7b4b4572 (diff)
Merge from bsd-4-0-0-branch.
Diffstat (limited to 'bsd-core/drm_auth.c')
-rw-r--r--bsd-core/drm_auth.c17
1 files changed, 6 insertions, 11 deletions
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);