Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / sis / sis_lock.h
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27
28 /*
29  * Authors:
30  *   Sung-Ching Lin <sclin@sis.com.tw>
31  *   Eric Anholt <anholt@FreeBSD.org>
32  */
33
34 #ifndef __SIS_LOCK_H
35 #define __SIS_LOCK_H
36
37 extern void sisGetLock( sisContextPtr smesa, GLuint flags );
38
39 #ifdef DEBUG_LOCKING
40 extern char *prevLockFile;
41 extern int prevLockLine;
42 #define DEBUG_LOCK() \
43   do { \
44     prevLockFile=(__FILE__); \
45     prevLockLine=(__LINE__); \
46   } while (0)
47 #define DEBUG_RESET() \
48   do { \
49     prevLockFile=NULL; \
50     prevLockLine=0; \
51   } while (0)
52 #define DEBUG_CHECK_LOCK() \
53   do { \
54       if(prevLockFile){ \
55         fprintf(stderr, "LOCK SET : %s:%d\n", __FILE__, __LINE__); \
56       } \
57   } while (0)
58 #else
59 #define DEBUG_LOCK()
60 #define DEBUG_RESET()
61 #define DEBUG_CHECK_LOCK()
62 #endif
63
64 /* Lock the hardware using the global current context */
65 #define LOCK_HARDWARE()                                                 \
66   do {                                                                  \
67     char __ret=0;                                                       \
68     mEndPrimitive();                                                    \
69     DEBUG_CHECK_LOCK();                                                 \
70     DRM_CAS( smesa->driHwLock, smesa->hHWContext,                       \
71              (DRM_LOCK_HELD | smesa->hHWContext), __ret );              \
72     if ( __ret != 0 )                                                   \
73         sisGetLock( smesa, 0 );                                                 \
74     DEBUG_LOCK();                                                       \
75   } while (0)
76
77 /* Unlock the hardware using the global current context */
78 #define UNLOCK_HARDWARE()                                               \
79   do {                                                                  \
80     mEndPrimitive();                                                    \
81     DRM_UNLOCK(smesa->driFd, smesa->driHwLock,                          \
82                smesa->hHWContext);                                      \
83     DEBUG_RESET();                                                      \
84   } while (0)
85
86 #endif