xref: /trunk/main/framework/inc/macros/debug/mutex.hxx (revision 01cec6d620143fc02deecf66cdb0013880d92ac2)
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 #ifndef __FRAMEWORK_MACROS_DEBUG_MUTEX_HXX_
23 #define __FRAMEWORK_MACROS_DEBUG_MUTEX_HXX_
24 
25 //*****************************************************************************************************************
26 //  special macros for mutex handling
27 //*****************************************************************************************************************
28 
29 #ifdef  ENABLE_MUTEXDEBUG
30 
31     //_____________________________________________________________________________________________________________
32     //  includes
33     //_____________________________________________________________________________________________________________
34 
35     #ifndef _RTL_STRBUF_HXX_
36     #include <rtl/strbuf.hxx>
37     #endif
38 
39     /*_____________________________________________________________________________________________________________
40         LOGFILE_MUTEX
41 
42         For follow macros we need a special log file. If user forget to specify anyone, we must do it for him!
43     _____________________________________________________________________________________________________________*/
44 
45     #ifndef LOGFILE_MUTEX
46         #define LOGFILE_MUTEX   "mutex.log"
47     #endif
48 
49     /*_____________________________________________________________________________________________________________
50         LOG_LOCKTYPE( _EFALLBACK, _ECURRENT )
51 
52         Write information about current set lock type for whole framework project to special file.
53     _____________________________________________________________________________________________________________*/
54 
55     #define LOG_LOCKTYPE( _EFALLBACK, _ECURRENT )                                                               \
56                 /* new scope to prevent us against multiple definitions of variables ... */                     \
57                 {                                                                                               \
58                     ::rtl::OStringBuffer _sBuffer( 256 );                                                       \
59                     _sBuffer.append( "Set framework lock type to fallback: \"" );                               \
60                     switch( _EFALLBACK )                                                                        \
61                     {                                                                                           \
62                         case E_NOTHING      :   _sBuffer.append( "E_NOTHING"    );                              \
63                                                 break;                                                          \
64                         case E_OWNMUTEX     :   _sBuffer.append( "E_OWNMUTEX"   );                              \
65                                                 break;                                                          \
66                         case E_SOLARMUTEX   :   _sBuffer.append( "E_SOLARMUTEX" );                              \
67                                                 break;                                                          \
68                         case E_FAIRRWLOCK   :   _sBuffer.append( "E_FAIRRWLOCK" );                              \
69                                                 break;                                                          \
70                     }                                                                                           \
71                     _sBuffer.append( "\"\n" );                                                                  \
72                     if( _EFALLBACK != _ECURRENT )                                                               \
73                     {                                                                                           \
74                         _sBuffer.append( "... environment overwrite framework lock type with: \"" );            \
75                         switch( _ECURRENT )                                                                     \
76                         {                                                                                       \
77                             case E_NOTHING      :   _sBuffer.append( "E_NOTHING"    );                          \
78                                                     break;                                                      \
79                             case E_OWNMUTEX     :   _sBuffer.append( "E_OWNMUTEX"   );                          \
80                                                     break;                                                      \
81                             case E_SOLARMUTEX   :   _sBuffer.append( "E_SOLARMUTEX" );                          \
82                                                     break;                                                      \
83                             case E_FAIRRWLOCK   :   _sBuffer.append( "E_FAIRRWLOCK" );                          \
84                                                     break;                                                      \
85                         }                                                                                       \
86                         _sBuffer.append( "\"\n" );                                                              \
87                     }                                                                                           \
88                     else                                                                                        \
89                     {                                                                                           \
90                         _sBuffer.append( "... use fallback, because user don't set another value!\n" );         \
91                     }                                                                                           \
92                     WRITE_LOGFILE( LOGFILE_MUTEX, _sBuffer.makeStringAndClear() )                               \
93                 }
94 
95 #else   // #ifdef ENABLE_MUTEXDEBUG
96 
97     /*_____________________________________________________________________________________________________________
98         If right testmode isn't set - implements these macro with normal functionality!
99         We need the guard but not the log mechanism.
100     _____________________________________________________________________________________________________________*/
101 
102     #undef  LOGFILE_MUTEX
103     #define LOG_LOCKTYPE( _EFALLBACK, _ECURRENT )
104 
105 #endif  // #ifdef ENABLE_MUTEXDEBUG
106 
107 //*****************************************************************************************************************
108 //  end of file
109 //*****************************************************************************************************************
110 
111 #endif  // #ifndef __FRAMEWORK_MACROS_DEBUG_MUTEX_HXX_
112