intel_lock.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028 
00029 #include "main/glheader.h"
00030 #include "pipe/p_thread.h"
00031 #include <GL/internal/glcore.h>
00032 #include "state_tracker/st_public.h"
00033 #include "intel_context.h"
00034 #include "i830_dri.h"
00035 
00036 
00037 
00038 pipe_static_mutex( lockMutex );
00039 
00040 
00041 static void
00042 intelContendedLock(struct intel_context *intel, uint flags)
00043 {
00044    __DRIdrawablePrivate *dPriv = intel->driDrawable;
00045    __DRIscreenPrivate *sPriv = intel->driScreen;
00046    struct intel_screen *intelScreen = intel_screen(sPriv);
00047    drmI830Sarea *sarea = intel->sarea;
00048 
00049    drmGetLock(intel->driFd, intel->hHWContext, flags);
00050 
00051    DBG(LOCK, "%s - got contended lock\n", __progname);
00052 
00053    /* If the window moved, may need to set a new cliprect now.
00054     *
00055     * NOTE: This releases and regains the hw lock, so all state
00056     * checking must be done *after* this call:
00057     */
00058    if (dPriv)
00059       DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
00060 
00061    if (sarea->width != intelScreen->front.width ||
00062        sarea->height != intelScreen->front.height) {
00063 
00064       intelUpdateScreenRotation(sPriv, sarea);
00065    }
00066 }
00067 
00068 
00069 /* Lock the hardware and validate our state.
00070  */
00071 void LOCK_HARDWARE( struct intel_context *intel )
00072 {
00073     char __ret = 0;
00074 
00075     pipe_mutex_lock(lockMutex);
00076     assert(!intel->locked);
00077 
00078     DRM_CAS(intel->driHwLock, intel->hHWContext,
00079             (DRM_LOCK_HELD|intel->hHWContext), __ret);
00080 
00081     if (__ret)
00082        intelContendedLock( intel, 0 );
00083 
00084     DBG(LOCK, "%s - locked\n", __progname);
00085 
00086     intel->locked = 1;
00087 }
00088 
00089 
00090 /* Unlock the hardware using the global current context
00091  */
00092 void UNLOCK_HARDWARE( struct intel_context *intel )
00093 {
00094    assert(intel->locked);
00095    intel->locked = 0;
00096 
00097    DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
00098 
00099    pipe_mutex_unlock(lockMutex);
00100 
00101    DBG(LOCK, "%s - unlocked\n", __progname);
00102 }

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4