removed detritus
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_lock.h
1 /* -*- mode: c; c-basic-offset: 3 -*-
2 *
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.h,v 1.3 2002/02/22 21:45:03 dawes Exp $ */
27
28 /*
29 * Original rewrite:
30 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
31 *
32 * Authors:
33 * Gareth Hughes <gareth@valinux.com>
34 *
35 */
36
37 #ifndef __TDFX_LOCK_H__
38 #define __TDFX_LOCK_H__
39
40 #ifdef GLX_DIRECT_RENDERING
41
42 /* You can turn this on to find locking conflicts.
43 */
44 #define DEBUG_LOCKING 0
45
46 #if DEBUG_LOCKING
47 extern char *prevLockFile;
48 extern int prevLockLine;
49
50 #define DEBUG_LOCK() \
51 do { \
52 prevLockFile = (__FILE__); \
53 prevLockLine = (__LINE__); \
54 } while (0)
55
56 #define DEBUG_RESET() \
57 do { \
58 prevLockFile = 0; \
59 prevLockLine = 0; \
60 } while (0)
61
62 #define DEBUG_CHECK_LOCK() \
63 do { \
64 if ( prevLockFile ) { \
65 fprintf( stderr, \
66 "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \
67 prevLockFile, prevLockLine, __FILE__, __LINE__ ); \
68 exit( 1 ); \
69 } \
70 } while (0)
71
72 #else
73
74 #define DEBUG_LOCK()
75 #define DEBUG_RESET()
76 #define DEBUG_CHECK_LOCK()
77
78 #endif /* DEBUG_LOCKING */
79
80
81 extern void tdfxGetLock( tdfxContextPtr fxMesa );
82
83
84 /* !!! We may want to separate locks from locks with validation.
85 This could be used to improve performance for those things
86 commands that do not do any drawing !!! */
87
88 #define DRM_LIGHT_LOCK_RETURN(fd,lock,context,__ret) \
89 do { \
90 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
91 if (__ret) drmGetLock(fd,context,0); \
92 } while(0)
93
94 #define LOCK_HARDWARE( fxMesa ) \
95 do { \
96 char __ret = 0; \
97 \
98 DEBUG_CHECK_LOCK(); \
99 DRM_CAS( fxMesa->driHwLock, fxMesa->hHWContext, \
100 DRM_LOCK_HELD | fxMesa->hHWContext, __ret ); \
101 if ( __ret ) { \
102 tdfxGetLock( fxMesa ); \
103 } \
104 DEBUG_LOCK(); \
105 } while (0)
106
107 /* Unlock the hardware using the global current context */
108 #define UNLOCK_HARDWARE( fxMesa ) \
109 do { \
110 DRM_UNLOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext ); \
111 DEBUG_RESET(); \
112 } while (0)
113
114 /*
115 * This pair of macros makes a loop over the drawing operations
116 * so it is not self contained and doesn't have the nice single
117 * statement semantics of most macros.
118 */
119 #define BEGIN_CLIP_LOOP(fxMesa) \
120 do { \
121 LOCK_HARDWARE( fxMesa ); \
122 BEGIN_CLIP_LOOP_LOCKED( fxMesa )
123
124 #define BEGIN_CLIP_LOOP_LOCKED(fxMesa) \
125 do { \
126 int _nc = fxMesa->numClipRects; \
127 while (_nc--) { \
128 if (fxMesa->numClipRects > 1) { \
129 int _height = fxMesa->screen_height; \
130 fxMesa->Glide.grClipWindow(fxMesa->pClipRects[_nc].x1, \
131 _height - fxMesa->pClipRects[_nc].y2, \
132 fxMesa->pClipRects[_nc].x2, \
133 _height - fxMesa->pClipRects[_nc].y1); \
134 }
135
136
137 #define END_CLIP_LOOP_LOCKED( fxMesa ) \
138 } \
139 } while (0)
140
141 #define END_CLIP_LOOP( fxMesa ) \
142 END_CLIP_LOOP_LOCKED( fxMesa ); \
143 UNLOCK_HARDWARE( fxMesa ); \
144 } while (0)
145
146
147 #endif /* GLX_DIRECT_RENDERING */
148
149 #endif /* __TDFX_LOCK_H__ */