1 | /* |
2 | * PROGRAM: MT debugging support. |
3 | * MODULE: Reasons.h |
4 | * DESCRIPTION: Tool to access latest history of taken locks. |
5 | * |
6 | * The contents of this file are subject to the Initial |
7 | * Developer's Public License Version 1.0 (the "License"); |
8 | * you may not use this file except in compliance with the |
9 | * License. You may obtain a copy of the License at |
10 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
11 | * |
12 | * Software distributed under the License is distributed AS IS, |
13 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
14 | * See the License for the specific language governing rights |
15 | * and limitations under the License. |
16 | * |
17 | * The Original Code was created by Alex Peshkov |
18 | * for the Firebird Open Source RDBMS project. |
19 | * |
20 | * Copyright (c) 2012 Alex Peshkov <peshkoff at mail.ru> |
21 | * and all contributors signed below. |
22 | * |
23 | * All Rights Reserved. |
24 | * Contributor(s): ______________________________________. |
25 | * |
26 | * |
27 | */ |
28 | |
29 | #ifndef FB_COMMON_CLASSES_REASONS |
30 | #define FB_COMMON_CLASSES_REASONS |
31 | |
32 | #include <string.h> |
33 | |
34 | // __func__ is according to C99, but let's better define it for better flexibility |
35 | // For example, MSVC 2005 does not support __func__ |
36 | #if defined _MSC_VER && (_MSC_VER <= 1600) |
37 | #define FB_FUNCTION __FUNCTION__ |
38 | #elif defined(__GNUC__) |
39 | #define FB_FUNCTION (__FILE__ ": " STRINGIZE(__LINE__) ) |
40 | #else |
41 | #define FB_FUNCTION __func__ |
42 | #endif |
43 | |
44 | namespace Firebird |
45 | { |
46 | class Reasons |
47 | { |
48 | public: |
49 | #ifndef DEV_BUILD |
50 | void reason(const char*) { } |
51 | #else |
52 | Reasons() |
53 | : frIndex(0) |
54 | { |
55 | memset(from, 0, sizeof(from)); |
56 | } |
57 | |
58 | void reason(const char* fr) |
59 | { |
60 | from[frIndex % FB_NELEM(from)] = fr; |
61 | frIndex++; |
62 | frIndex %= FB_NELEM(from); |
63 | } |
64 | |
65 | private: |
66 | const char* from[8]; |
67 | unsigned frIndex; |
68 | #endif |
69 | }; |
70 | } // namespace Firebird |
71 | |
72 | #endif // FB_COMMON_CLASSES_REASONS |
73 | |