r200 driver, brought over by Jon Smirl
[mesa.git] / src / mesa / drivers / dri / r200 / r200_lock.h
1 /* $XFree86$ */
2 /**************************************************************************
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #ifndef __R200_LOCK_H__
37 #define __R200_LOCK_H__
38
39 #ifdef GLX_DIRECT_RENDERING
40
41 extern void r200GetLock( r200ContextPtr rmesa, GLuint flags );
42
43 /* Turn DEBUG_LOCKING on to find locking conflicts.
44 */
45 #define DEBUG_LOCKING 0
46
47 #if DEBUG_LOCKING
48 extern char *prevLockFile;
49 extern int prevLockLine;
50
51 #define DEBUG_LOCK() \
52 do { \
53 prevLockFile = (__FILE__); \
54 prevLockLine = (__LINE__); \
55 } while (0)
56
57 #define DEBUG_RESET() \
58 do { \
59 prevLockFile = 0; \
60 prevLockLine = 0; \
61 } while (0)
62
63 #define DEBUG_CHECK_LOCK() \
64 do { \
65 if ( prevLockFile ) { \
66 fprintf( stderr, \
67 "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \
68 prevLockFile, prevLockLine, __FILE__, __LINE__ ); \
69 exit( 1 ); \
70 } \
71 } while (0)
72
73 #else
74
75 #define DEBUG_LOCK()
76 #define DEBUG_RESET()
77 #define DEBUG_CHECK_LOCK()
78
79 #endif
80
81 /*
82 * !!! We may want to separate locks from locks with validation. This
83 * could be used to improve performance for those things commands that
84 * do not do any drawing !!!
85 */
86
87
88 /* Lock the hardware and validate our state.
89 */
90 #define LOCK_HARDWARE( rmesa ) \
91 do { \
92 char __ret = 0; \
93 DEBUG_CHECK_LOCK(); \
94 DRM_CAS( rmesa->dri.hwLock, rmesa->dri.hwContext, \
95 (DRM_LOCK_HELD | rmesa->dri.hwContext), __ret ); \
96 if ( __ret ) \
97 r200GetLock( rmesa, 0 ); \
98 DEBUG_LOCK(); \
99 } while (0)
100
101 /* Unlock the hardware.
102 */
103 #define UNLOCK_HARDWARE( rmesa ) \
104 do { \
105 DRM_UNLOCK( rmesa->dri.fd, \
106 rmesa->dri.hwLock, \
107 rmesa->dri.hwContext ); \
108 DEBUG_RESET(); \
109 } while (0)
110
111 #endif
112 #endif /* __R200_LOCK_H__ */