1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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 **************************************************************************/
29 #include "pipe/p_thread.h"
30 #include "dri_context.h"
33 pipe_static_mutex( lockMutex
);
36 dri_contended_lock(struct dri_context
*ctx
)
38 __DRIdrawablePrivate
*dPriv
= ctx
->dPriv
;
39 __DRIcontextPrivate
*cPriv
= ctx
->cPriv
;
40 __DRIscreenPrivate
*sPriv
= cPriv
->driScreenPriv
;
42 drmGetLock(sPriv
->fd
, cPriv
->hHWContext
, 0);
44 /* Perform round trip communication with server (including dropping
45 * and retaking the above lock) to update window dimensions:
48 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
52 /* Lock the hardware and validate our state.
54 void dri_lock_hardware( struct dri_context
*ctx
)
56 __DRIcontextPrivate
*cPriv
= ctx
->cPriv
;
57 __DRIscreenPrivate
*sPriv
= cPriv
->driScreenPriv
;
60 pipe_mutex_lock(lockMutex
);
63 DRM_CAS((drmLock
*) &sPriv
->pSAREA
->lock
,
65 (DRM_LOCK_HELD
| cPriv
->hHWContext
),
69 dri_contended_lock( ctx
);
75 /* Unlock the hardware using the global current context
77 void dri_unlock_hardware( struct dri_context
*ctx
)
79 __DRIcontextPrivate
*cPriv
= ctx
->cPriv
;
80 __DRIscreenPrivate
*sPriv
= cPriv
->driScreenPriv
;
86 (drmLock
*) &sPriv
->pSAREA
->lock
,
89 pipe_mutex_unlock(lockMutex
);