Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / mach64 / mach64_lock.h
1 /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3  * Copyright 2000 Gareth Hughes
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /*
26  * Authors:
27  *      Gareth Hughes <gareth@valinux.com>
28  *
29  */
30
31 #ifndef __MACH64_LOCK_H__
32 #define __MACH64_LOCK_H__
33
34 extern void mach64GetLock( mach64ContextPtr mmesa, GLuint flags );
35
36
37 /* Turn DEBUG_LOCKING on to find locking conflicts.
38  */
39 #define DEBUG_LOCKING   1
40
41 #if DEBUG_LOCKING
42 extern char *prevLockFile;
43 extern int   prevLockLine;
44
45 #define DEBUG_LOCK()                                                    \
46    do {                                                                 \
47       prevLockFile = (__FILE__);                                        \
48       prevLockLine = (__LINE__);                                        \
49    } while (0)
50
51 #define DEBUG_RESET()                                                   \
52    do {                                                                 \
53       prevLockFile = 0;                                                 \
54       prevLockLine = 0;                                                 \
55    } while (0)
56
57 #define DEBUG_CHECK_LOCK()                                              \
58    do {                                                                 \
59       if ( prevLockFile ) {                                             \
60          fprintf( stderr,                                               \
61                   "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n",    \
62                   prevLockFile, prevLockLine, __FILE__, __LINE__ );     \
63          exit( 1 );                                                     \
64       }                                                                 \
65    } while (0)
66
67 #else
68
69 #define DEBUG_LOCK()
70 #define DEBUG_RESET()
71 #define DEBUG_CHECK_LOCK()
72
73 #endif
74
75 /*
76  * !!! We may want to separate locks from locks with validation.  This
77  * could be used to improve performance for those things commands that
78  * do not do any drawing !!!
79  */
80
81 /* Lock the hardware and validate our state.
82  */
83 #define LOCK_HARDWARE( mmesa )                                          \
84    do {                                                                 \
85       char __ret = 0;                                                   \
86       DEBUG_CHECK_LOCK();                                               \
87       DRM_CAS( mmesa->driHwLock, mmesa->hHWContext,                     \
88                (DRM_LOCK_HELD | mmesa->hHWContext), __ret );            \
89       if ( __ret )                                                      \
90          mach64GetLock( mmesa, 0 );                                     \
91       DEBUG_LOCK();                                                     \
92    } while (0)
93
94 /* Unlock the hardware.
95  */
96 #define UNLOCK_HARDWARE( mmesa )                                        \
97    do {                                                                 \
98       DRM_UNLOCK( mmesa->driFd,                                         \
99                   mmesa->driHwLock,                                     \
100                   mmesa->hHWContext );                                  \
101       DEBUG_RESET();                                                    \
102    } while (0)
103
104 #endif /* __MACH64_LOCK_H__ */