Merge branch 'master' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_lock.h
1 #ifndef __GAMMA_LOCK_H__
2 #define __GAMMA_LOCK_H__
3
4 extern void gammaGetLock( gammaContextPtr gmesa, GLuint flags );
5
6 /* Turn DEBUG_LOCKING on to find locking conflicts.
7 */
8 #define DEBUG_LOCKING 0
9
10 #if DEBUG_LOCKING
11 extern char *prevLockFile;
12 extern int prevLockLine;
13
14 #define DEBUG_LOCK() \
15 do { \
16 prevLockFile = (__FILE__); \
17 prevLockLine = (__LINE__); \
18 } while (0)
19
20 #define DEBUG_RESET() \
21 do { \
22 prevLockFile = 0; \
23 prevLockLine = 0; \
24 } while (0)
25
26 #define DEBUG_CHECK_LOCK() \
27 do { \
28 if ( prevLockFile ) { \
29 fprintf( stderr, \
30 "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \
31 prevLockFile, prevLockLine, __FILE__, __LINE__ ); \
32 exit( 1 ); \
33 } \
34 } while (0)
35
36 #else
37
38 #define DEBUG_LOCK()
39 #define DEBUG_RESET()
40 #define DEBUG_CHECK_LOCK()
41
42 #endif
43
44 /*
45 * !!! We may want to separate locks from locks with validation. This
46 * could be used to improve performance for those things commands that
47 * do not do any drawing !!!
48 */
49
50 /* Lock the hardware and validate our state.
51 */
52 #define LOCK_HARDWARE( gmesa ) \
53 do { \
54 char __ret = 0; \
55 DEBUG_CHECK_LOCK(); \
56 DRM_CAS( gmesa->driHwLock, gmesa->hHWContext, \
57 (DRM_LOCK_HELD | gmesa->hHWContext), __ret ); \
58 if ( __ret ) \
59 gammaGetLock( gmesa, 0 ); \
60 DEBUG_LOCK(); \
61 } while (0)
62
63 /* Unlock the hardware.
64 */
65 #define UNLOCK_HARDWARE( gmesa ) \
66 do { \
67 DRM_UNLOCK( gmesa->driFd, \
68 gmesa->driHwLock, \
69 gmesa->hHWContext ); \
70 DEBUG_RESET(); \
71 } while (0)
72
73 #define GAMMAHW_LOCK( gmesa ) \
74 DRM_UNLOCK(gmesa->driFd, gmesa->driHwLock, gmesa->hHWContext); \
75 DRM_SPINLOCK(&gmesa->driScreen->pSAREA->drawable_lock, \
76 gmesa->driScreen->drawLockID); \
77 VALIDATE_DRAWABLE_INFO_NO_LOCK(gmesa);
78
79 #define GAMMAHW_UNLOCK( gmesa ) \
80 DRM_SPINUNLOCK(&gmesa->driScreen->pSAREA->drawable_lock, \
81 gmesa->driScreen->drawLockID); \
82 VALIDATE_DRAWABLE_INFO_NO_LOCK_POST(gmesa);
83
84 #endif /* __GAMMA_LOCK_H__ */