xref: /trunk/main/framework/inc/macros/debug/mutex.hxx (revision f8e07b45)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_MACROS_DEBUG_MUTEX_HXX_
25 #define __FRAMEWORK_MACROS_DEBUG_MUTEX_HXX_
26 
27 //*****************************************************************************************************************
28 //	special macros for mutex handling
29 //*****************************************************************************************************************
30 
31 #ifdef	ENABLE_MUTEXDEBUG
32 
33 	//_____________________________________________________________________________________________________________
34 	//	includes
35 	//_____________________________________________________________________________________________________________
36 
37 	#ifndef _RTL_STRBUF_HXX_
38 	#include <rtl/strbuf.hxx>
39 	#endif
40 
41 	/*_____________________________________________________________________________________________________________
42 		LOGFILE_MUTEX
43 
44 		For follow macros we need a special log file. If user forget to specify anyone, we must do it for him!
45 	_____________________________________________________________________________________________________________*/
46 
47 	#ifndef	LOGFILE_MUTEX
48         #define LOGFILE_MUTEX   "mutex.log"
49 	#endif
50 
51 	/*_____________________________________________________________________________________________________________
52         LOG_LOCKTYPE( _EFALLBACK, _ECURRENT )
53 
54         Write informations about current set lock type for whole framework project to special file.
55 	_____________________________________________________________________________________________________________*/
56 
57     #define LOG_LOCKTYPE( _EFALLBACK, _ECURRENT )                                                               \
58                 /* new scope to prevent us against multiple definitions of variables ... */                     \
59                 {                                                                                               \
60                     ::rtl::OStringBuffer _sBuffer( 256 );                                                       \
61                     _sBuffer.append( "Set framework lock type to fallback: \"" );                               \
62                     switch( _EFALLBACK )                                                                        \
63                     {                                                                                           \
64                         case E_NOTHING      :   _sBuffer.append( "E_NOTHING"    );                              \
65                                                 break;                                                          \
66                         case E_OWNMUTEX     :   _sBuffer.append( "E_OWNMUTEX"   );                              \
67                                                 break;                                                          \
68                         case E_SOLARMUTEX   :   _sBuffer.append( "E_SOLARMUTEX" );                              \
69                                                 break;                                                          \
70                         case E_FAIRRWLOCK   :   _sBuffer.append( "E_FAIRRWLOCK" );                              \
71                                                 break;                                                          \
72                     }                                                                                           \
73                     _sBuffer.append( "\"\n" );                                                                  \
74                     if( _EFALLBACK != _ECURRENT )                                                               \
75                     {                                                                                           \
76                         _sBuffer.append( "... environment overwrite framework lock type with: \"" );            \
77                         switch( _ECURRENT )                                                                     \
78                         {                                                                                       \
79                             case E_NOTHING      :   _sBuffer.append( "E_NOTHING"    );                          \
80                                                     break;                                                      \
81                             case E_OWNMUTEX     :   _sBuffer.append( "E_OWNMUTEX"   );                          \
82                                                     break;                                                      \
83                             case E_SOLARMUTEX   :   _sBuffer.append( "E_SOLARMUTEX" );                          \
84                                                     break;                                                      \
85                             case E_FAIRRWLOCK   :   _sBuffer.append( "E_FAIRRWLOCK" );                          \
86                                                     break;                                                      \
87                         }                                                                                       \
88                         _sBuffer.append( "\"\n" );                                                              \
89                     }                                                                                           \
90                     else                                                                                        \
91                     {                                                                                           \
92                         _sBuffer.append( "... use fallback, because user don't set another value!\n" );         \
93                     }                                                                                           \
94                     WRITE_LOGFILE( LOGFILE_MUTEX, _sBuffer.makeStringAndClear() )                               \
95                 }
96 
97 #else	// #ifdef ENABLE_MUTEXDEBUG
98 
99 	/*_____________________________________________________________________________________________________________
100 		If right testmode is'nt set - implements these macro with normal functionality!
101 		We need the guard but not the log mechanism.
102 	_____________________________________________________________________________________________________________*/
103 
104 	#undef	LOGFILE_MUTEX
105     #define LOG_LOCKTYPE( _EFALLBACK, _ECURRENT )
106 
107 #endif	// #ifdef ENABLE_MUTEXDEBUG
108 
109 //*****************************************************************************************************************
110 //	end of file
111 //*****************************************************************************************************************
112 
113 #endif	// #ifndef __FRAMEWORK_MACROS_DEBUG_MUTEX_HXX_
114