Merge commit 'origin/gallium-0.1'
[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
27 /*
28 * Original rewrite:
29 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
30 *
31 * Authors:
32 * Gareth Hughes <gareth@valinux.com>
33 *
34 */
35
36 #ifndef __TDFX_LOCK_H__
37 #define __TDFX_LOCK_H__
38
39 /* You can turn this on to find locking conflicts.
40 */
41 #define DEBUG_LOCKING 0
42
43 #if DEBUG_LOCKING
44 extern char *prevLockFile;
45 extern int prevLockLine;
46
47 #define DEBUG_LOCK() \
48 do { \
49 prevLockFile = (__FILE__); \
50 prevLockLine = (__LINE__); \
51 } while (0)
52
53 #define DEBUG_RESET() \
54 do { \
55 prevLockFile = 0; \
56 prevLockLine = 0; \
57 } while (0)
58
59 #define DEBUG_CHECK_LOCK() \
60 do { \
61 if ( prevLockFile ) { \
62 fprintf( stderr, \
63 "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \
64 prevLockFile, prevLockLine, __FILE__, __LINE__ ); \
65 exit( 1 ); \
66 } \
67 } while (0)
68
69 #else
70
71 #define DEBUG_LOCK()
72 #define DEBUG_RESET()
73 #define DEBUG_CHECK_LOCK()
74
75 #endif /* DEBUG_LOCKING */
76
77
78 extern void tdfxGetLock( tdfxContextPtr fxMesa );
79
80
81 /* !!! We may want to separate locks from locks with validation.
82 This could be used to improve performance for those things
83 commands that do not do any drawing !!! */
84
85 #define DRM_LIGHT_LOCK_RETURN(fd,lock,context,__ret) \
86 do { \
87 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
88 if (__ret) drmGetLock(fd,context,0); \
89 } while(0)
90
91 #define LOCK_HARDWARE( fxMesa ) \
92 do { \
93 char __ret = 0; \
94 \
95 DEBUG_CHECK_LOCK(); \
96 DRM_CAS( fxMesa->driHwLock, fxMesa->hHWContext, \
97 DRM_LOCK_HELD | fxMesa->hHWContext, __ret ); \
98 if ( __ret ) { \
99 tdfxGetLock( fxMesa ); \
100 } \
101 DEBUG_LOCK(); \
102 } while (0)
103
104 /* Unlock the hardware using the global current context */
105 #define UNLOCK_HARDWARE( fxMesa ) \
106 do { \
107 DRM_UNLOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext ); \
108 DEBUG_RESET(); \
109 } while (0)
110
111 /*
112 * This pair of macros makes a loop over the drawing operations
113 * so it is not self contained and doesn't have the nice single
114 * statement semantics of most macros.
115 */
116 #define BEGIN_CLIP_LOOP(fxMesa) \
117 do { \
118 LOCK_HARDWARE( fxMesa ); \
119 BEGIN_CLIP_LOOP_LOCKED( fxMesa )
120
121 #define BEGIN_CLIP_LOOP_LOCKED(fxMesa) \
122 do { \
123 int _nc = fxMesa->numClipRects; \
124 while (_nc--) { \
125 if (fxMesa->numClipRects > 1) { \
126 int _height = fxMesa->screen_height; \
127 fxMesa->Glide.grClipWindow(fxMesa->pClipRects[_nc].x1, \
128 _height - fxMesa->pClipRects[_nc].y2, \
129 fxMesa->pClipRects[_nc].x2, \
130 _height - fxMesa->pClipRects[_nc].y1); \
131 }
132
133
134 #define END_CLIP_LOOP_LOCKED( fxMesa ) \
135 } \
136 } while (0)
137
138 #define END_CLIP_LOOP( fxMesa ) \
139 END_CLIP_LOOP_LOCKED( fxMesa ); \
140 UNLOCK_HARDWARE( fxMesa ); \
141 } while (0)
142
143 #endif /* __TDFX_LOCK_H__ */