Had some odd problems with add and temps so doing it with mad. Adding some MAD_2...
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_lock.h
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /*
31 * Authors:
32 * Keith Whitwell <keith@tungstengraphics.com>
33 */
34
35 #ifndef __RADEON_LOCK_H__
36 #define __RADEON_LOCK_H__
37
38 #include "r200_ioctl.h"
39
40 extern void radeonGetLock(radeonContextPtr radeon, 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 /* Lock the hardware and validate our state.
87 */
88 #define LOCK_HARDWARE( radeon ) \
89 do { \
90 char __ret = 0; \
91 DEBUG_CHECK_LOCK(); \
92 DRM_CAS( (radeon)->dri.hwLock, (radeon)->dri.hwContext, \
93 (DRM_LOCK_HELD | (radeon)->dri.hwContext), __ret ); \
94 if ( __ret ) \
95 radeonGetLock( (radeon), 0 ); \
96 DEBUG_LOCK(); \
97 } while (0)
98
99 #define UNLOCK_HARDWARE( radeon ) \
100 do { \
101 DRM_UNLOCK( (radeon)->dri.fd, \
102 (radeon)->dri.hwLock, \
103 (radeon)->dri.hwContext ); \
104 DEBUG_RESET(); \
105 if (IS_FAMILY_R200((radeon))) { \
106 r200ContextPtr __r200 = (r200ContextPtr)(radeon); \
107 if (__r200->save_on_next_unlock) \
108 r200SaveHwState( __r200 ); \
109 __r200->save_on_next_unlock = GL_FALSE; \
110 } \
111 } while (0)
112
113 #endif /* __RADEON_LOCK_H__ */