Merge branch 'origin' into glsl-compiler-1
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_lock.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_lock.h,v 1.3 2002/10/30 12:51:55 alanh Exp $ */
2 /**************************************************************************
3
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 VA Linux Systems Inc., Fremont, California.
6
7 All Rights Reserved.
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 * Kevin E. Martin <martin@valinux.com>
34 * Gareth Hughes <gareth@valinux.com>
35 */
36
37 #ifndef __RADEON_LOCK_H__
38 #define __RADEON_LOCK_H__
39
40 extern void radeonGetLock( radeonContextPtr rmesa, GLuint flags );
41
42 /* Turn DEBUG_LOCKING 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
79
80 /*
81 * !!! We may want to separate locks from locks with validation. This
82 * could be used to improve performance for those things commands that
83 * do not do any drawing !!!
84 */
85
86
87 /* Lock the hardware and validate our state.
88 */
89 #define LOCK_HARDWARE( rmesa ) \
90 do { \
91 char __ret = 0; \
92 DEBUG_CHECK_LOCK(); \
93 DRM_CAS( rmesa->dri.hwLock, rmesa->dri.hwContext, \
94 (DRM_LOCK_HELD | rmesa->dri.hwContext), __ret ); \
95 if ( __ret ) \
96 radeonGetLock( rmesa, 0 ); \
97 DEBUG_LOCK(); \
98 } while (0)
99
100 #define UNLOCK_HARDWARE( rmesa ) \
101 do { \
102 DRM_UNLOCK( rmesa->dri.fd, \
103 rmesa->dri.hwLock, \
104 rmesa->dri.hwContext ); \
105 DEBUG_RESET(); \
106 } while (0)
107
108 #endif /* __RADEON_LOCK_H__ */