e7173f77fb59de5896a6f555b6ecd019c2ae3bc2
[platform/core/system/swap-probe.git] / probe_thread / da_sync.h
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: 
7  *
8  * Woojin Jung <woojin2.jung@samsung.com>
9  * Jaewon Lim <jaewon81.lim@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  * 
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  * 
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  * 
29  */
30
31 #ifndef __DA_SYNC_H__
32 #define __DA_SYNC_H__
33
34 #include "daprobe.h"
35
36 #ifdef __cplusplus
37 extern "C"{
38 #endif
39
40 int real_pthread_mutex_lock(pthread_mutex_t *mutex);
41 int real_pthread_mutex_unlock(pthread_mutex_t *mutex);
42
43 #define BEFORE_ORIGINAL_SYNC(FUNCNAME, LIBNAME)         \
44         DECLARE_VARIABLE_STANDARD; log_t log;                   \
45         GET_REAL_FUNC(FUNCNAME, LIBNAME);                               \
46         PRE_PROBEBLOCK()
47
48 #define POST_PROBEBLOCK_MIDDLE_SYNCVAL(SYNCVAL, SYNCTYPE, APITYPE)      \
49         log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d",    \
50                         SYNCVAL, SYNCTYPE, APITYPE)
51
52 #define POST_PROBEBLOCK_MIDDLE_NOSYNCVAL(SYNCTYPE, APITYPE)                     \
53         log.length += sprintf(log.data + log.length, "`,0`,%d`,%d",             \
54                         SYNCTYPE, APITYPE)
55
56 #define AFTER_ORIGINAL_SYNCVAL_RET(RTYPE, RVAL, SYNCVAL, SYNCTYPE, APITYPE, INPUTFORMAT, ...)   \
57         POST_PROBEBLOCK_BEGIN(LC_SYNC, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__);                                          \
58         POST_PROBEBLOCK_MIDDLE_SYNCVAL(SYNCVAL, SYNCTYPE, APITYPE);                                                                     \
59         POST_PROBEBLOCK_CALLSTACK();                                                                                                                            \
60         POST_PROBEBLOCK_END()
61
62 #define AFTER_ORIGINAL_NOSYNCVAL_RET(RTYPE, RVAL, SYNCTYPE, APITYPE, INPUTFORMAT, ...)                  \
63         POST_PROBEBLOCK_BEGIN(LC_SYNC, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__);                                          \
64         POST_PROBEBLOCK_MIDDLE_NOSYNCVAL(SYNCTYPE, APITYPE);                                                                            \
65         POST_PROBEBLOCK_CALLSTACK();                                                                                                                            \
66         POST_PROBEBLOCK_END()
67
68 #define AFTER_PACK_ORIGINAL_SYNC(RVAL, SYNCVAL, SYNCTYPE, APITYPE, INPUTFORMAT, ...)                    \
69         POST_PACK_PROBEBLOCK_BEGIN();                                           \
70         PREPARE_LOCAL_BUF();                                                                                                                                            \
71         PACK_COMMON_BEGIN(MSG_PROBE_SYNC, LC_SYNC, INPUTFORMAT, __VA_ARGS__);                                           \
72         PACK_COMMON_END(RVAL, errno, blockresult);                                                                                                      \
73         PACK_SYNC(SYNCVAL, SYNCTYPE, APITYPE);                                                                                                          \
74         FLUSH_LOCAL_BUF();                                                                                                                                                      \
75         POST_PACK_PROBEBLOCK_END()
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif // __DA_SYNC_H__
82