1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "main/glheader.h"
29 #include "glapi/glthread.h"
30 #include <GL/internal/glcore.h>
32 #include "nouveau_context.h"
33 #include "nouveau_screen.h"
35 _glthread_DECLARE_STATIC_MUTEX( lockMutex
);
38 nouveau_contended_lock(struct nouveau_context
*nv
, GLuint flags
)
40 __DRIdrawablePrivate
*dPriv
= nv
->dri_drawable
;
41 __DRIscreenPrivate
*sPriv
= nv
->dri_screen
;
42 struct nouveau_screen
*nv_screen
= nv
->nv_screen
;
43 struct nouveau_device
*dev
= nv_screen
->device
;
44 struct nouveau_device_priv
*nvdev
= nouveau_device(dev
);
46 drmGetLock(nvdev
->fd
, nvdev
->ctx
, flags
);
48 /* If the window moved, may need to set a new cliprect now.
50 * NOTE: This releases and regains the hw lock, so all state
51 * checking must be done *after* this call:
54 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
57 /* Lock the hardware and validate our state.
60 LOCK_HARDWARE(struct nouveau_context
*nv
)
62 struct nouveau_screen
*nv_screen
= nv
->nv_screen
;
63 struct nouveau_device
*dev
= nv_screen
->device
;
64 struct nouveau_device_priv
*nvdev
= nouveau_device(dev
);
67 _glthread_LOCK_MUTEX(lockMutex
);
70 DRM_CAS(nvdev
->lock
, nvdev
->ctx
,
71 (DRM_LOCK_HELD
| nvdev
->ctx
), __ret
);
74 nouveau_contended_lock(nv
, 0);
79 /* Unlock the hardware using the global current context
82 UNLOCK_HARDWARE(struct nouveau_context
*nv
)
84 struct nouveau_screen
*nv_screen
= nv
->nv_screen
;
85 struct nouveau_device
*dev
= nv_screen
->device
;
86 struct nouveau_device_priv
*nvdev
= nouveau_device(dev
);
89 nv
->locked
= GL_FALSE
;
91 DRM_UNLOCK(nvdev
->fd
, nvdev
->lock
, nvdev
->ctx
);
93 _glthread_UNLOCK_MUTEX(lockMutex
);